function showResult() {
  clearInterval(timerInterval); // resets timer
  secondsLeft = document.querySelector(".timer_sec").textContent;
  info_box.classList.remove("activeInfo"); //hide info box
  quiz_box.classList.remove("activeQuiz"); //hide quiz box
  result_box.classList.add("activeResult"); //show result box
  var scoreText = result_box.querySelector(".score_text");
  var scoreTag = '<span>All done! Your final score is ' + secondsLeft + '</span>'; //shows user their score
  scoreText.innerHTML = scoreTag; //pushes info to page

  var formInput = document.getElementById("formInput");

  // to display a message based on criteria below for setting initials
  function displayMessage(type, message) {
    var msgDiv = document.getElementById("msg");
    msgDiv.textContent = message;
    msgDiv.setAttribute("class", type);
  }

  // On submit button clicked...

  submitBtn.addEventListener("click", function (event) {
    event.preventDefault();


// stores user info
    var user = {
      initials: formInput.value.trim(),
      score: secondsLeft,
    };

    // validate the fields
    if (formInput.value === "") { // tells user their input can't be blank to save a highscore
      displayMessage("error", "Initials cannot be blank");
    }
    else if (formInput.value.length > 3) { //if pw is longer than 3 characters show error & message
      displayMessage("error", "Initials cannot be longer than 3 characters")
    }
    else {
      displayMessage("success", "Registered successfully"); //displays registered successfully & shows highscore board
      result_box.classList.remove("activeResult"); //hide result box
      restart_quiz2.textContent = "Replay Quiz";

      highscore_box.classList.add("activeResult"); //show result box

      // set new submission
      console.log(user);
      var userString = JSON.stringify(user);
      JSON.parse(userString);
      localStorage.setItem("user", userString);
      highscoresList.push(user.initials + " " + user.score);
      formInput.value = "";
      displayMessage("", "");
      renderHighscores();
      timeValue = 60;
    }


  });

  var highscorersList = document.querySelector(".hscores");
// adds highscore to scoreoard
  function renderHighscores() {

    for (newHS; newHS < highscoresList.length; newHS++) {
      var highscore = highscoresList[newHS];
      var li = document.createElement("li");
      li.textContent = highscore;
      highscorersList.appendChild(li);
    }
  }
}
// Shows the score of the user
Shows the score of the user
Shows the score of the user
function showResult() {
  clearInterval(timerInterval); 
  secondsLeft = document.querySelector(".timer_sec").textContent;
  info_box.classList.remove("activeInfo"); 
  quiz_box.classList.remove("activeQuiz"); 
  result_box.classList.add("activeResult"); 
  var scoreText = result_box.querySelector(".score_text");
  var scoreTag = '<span>All done! Your final score is ' + secondsLeft + '</span>'; 
  scoreText.innerHTML = scoreTag; 
  var formInput = document.getElementById("formInput");
  function displayMessage(type, message) {
    var msgDiv = document.getElementById("msg");
    msgDiv.textContent = message;
    msgDiv.setAttribute("class", type);
  }
  submitBtn.addEventListener("click", function (event) {
    event.preventDefault();
    var user = {
      initials: formInput.value.trim(),
      score: secondsLeft,
    };
    if (formInput.value === "") { 
      displayMessage("error", "Initials cannot be blank");
    }
    else if (formInput.value.length > 3) { 
      displayMessage("error", "Initials cannot be longer than 3 characters")
    }
    else {
      displayMessage("success", "Registered successfully"); 
      result_box.classList.remove("activeResult"); 
      restart_quiz2.textContent = "Replay Quiz";
      highscore_box.classList.add("activeResult"); 
      console.log(user);
      var userString = JSON.stringify(user);
      JSON.parse(userString);
      localStorage.setItem("user", userString);
      highscoresList.push(user.initials + " " + user.score);
      formInput.value = "";
      displayMessage("", "");
      renderHighscores();
      timeValue = 60;
    }
  });
  var highscorersList = document.querySelector(".hscores");
  function renderHighscores() {
    for (newHS; newHS < highscoresList.length; newHS++) {
      var highscore = highscoresList[newHS];
      var li = document.createElement("li");
      li.textContent = highscore;
      highscorersList.appendChild(li);
    }
  }
}
function showResult ( ) { clearInterval ( timerInterval ) ; secondsLeft = document . querySelector ( ".timer_sec" ) . textContent ; info_box . classList . remove ( "activeInfo" ) ; quiz_box . classList . remove ( "activeQuiz" ) ; result_box . classList . add ( "activeResult" ) ; var scoreText = result_box . querySelector ( ".score_text" ) ; var scoreTag = '<span>All done! Your final score is ' + secondsLeft + '</span>' ; scoreText . innerHTML = scoreTag ; var formInput = document . getElementById ( "formInput" ) ; function displayMessage ( type , message ) { var msgDiv = document . getElementById ( "msg" ) ; msgDiv . textContent = message ; msgDiv . setAttribute ( "class" , type ) ; } submitBtn . addEventListener ( "click" , function ( event ) { event . preventDefault ( ) ; var user = { initials : formInput . value . trim ( ) , score : secondsLeft , } ; if ( formInput . value === "" ) { displayMessage ( "error" , "Initials cannot be blank" ) ; } else if ( formInput . value . length > 3 ) { displayMessage ( "error" , "Initials cannot be longer than 3 characters" ) } else { displayMessage ( "success" , "Registered successfully" ) ; result_box . classList . remove ( "activeResult" ) ; restart_quiz2 . textContent = "Replay Quiz" ; highscore_box . classList . add ( "activeResult" ) ; console . log ( user ) ; var userString = JSON . stringify ( user ) ; JSON . parse ( userString ) ; localStorage . setItem ( "user" , userString ) ; highscoresList . push ( user . initials + " " + user . score ) ; formInput . value = "" ; displayMessage ( "" , "" ) ; renderHighscores ( ) ; timeValue = 60 ; } } ) ; var highscorersList = document . querySelector ( ".hscores" ) ; function renderHighscores ( ) { for ( newHS ; newHS < highscoresList . length ; newHS ++ ) { var highscore = highscoresList [ newHS ] ; var li = document . createElement ( "li" ) ; li . textContent = highscore ; highscorersList . appendChild ( li ) ; } } }
Shows the score of the user
Shows the score of the user
// resets timer //hide info box //hide quiz box //show result box //shows user their score //pushes info to page // to display a message based on criteria below for setting initials // On submit button clicked... // stores user info // validate the fields // tells user their input can't be blank to save a highscore //if pw is longer than 3 characters show error & message //displays registered successfully & shows highscore board //hide result box //show result box // set new submission // adds highscore to scoreoard