Undefined global variables

Question

I know that this question may be a "dumb" one but just forgive me for this :( I was doing a quiz-time application but just got a problem :( my two global variable are not defined which are "score" and "solvedQuestions" although there's no variable has the same name... I'm doing this for the awesome french girl in my English council <3
here's the code

var score = 0;
var solvedQuestions = 0;
//prototype
function Question(quest, option1, option2, option3, correct) {
  this.quest = quest;
  this.option1 = option1;
  this.option2 = option2;
  this.option3 = option3;
  this.correct = correct;

}
//creating questions
var question1 = new Question("1 + 1", 2, 3, 3, 1);
var question2 = new Question("2 + 2", 4, 3, 3, 2);
var question3 = new Question("3 + 3", 6, 3, 3, 3);
var question4 = new Question("4 + 4", 8, 3, 3, 1);
var question5 = new Question("5 + 5", 10, 3, 3, 2);
var question6 = new Question("6 + 6", 12, 3, 3, 3);
//the questions array
var questions = [];
//pushing questions to array
questions.push(question1);
questions.push(question2);
questions.push(question3);
questions.push(question4);
questions.push(question5);
questions.push(question6);
var randomQuestionIndex = Math.floor(Math.random() * 6);
// Builds the questions in the first loop
function QuestionPre() {
  randomQuestionIndex = Math.floor(Math.random() * 6);
  document.querySelector("#question").innerHTML = questions[randomQuestionIndex].quest;
  document.querySelector(".option-1").innerHTML = questions[randomQuestionIndex].option1;
  document.querySelector(".option-2").innerHTML = questions[randomQuestionIndex].option2;
  document.querySelector(".option-3").innerHTML = questions[randomQuestionIndex].option3;

}
QuestionPre();
// resets them after answering
function QuestionReset() {
  randomQuestionIndex = Math.floor(Math.random() * 6);
  document.querySelector("#question").innerHTML = questions[randomQuestionIndex].quest;
  document.querySelector(".option-1").innerHTML = questions[randomQuestionIndex].option1;
  document.querySelector(".option-2").innerHTML = questions[randomQuestionIndex].option2;
  document.querySelector(".option-3").innerHTML = questions[randomQuestionIndex].option3;
}
document.querySelector(".lock-btn").addEventListener("click", function() {
  if (document.querySelector(".option-" + questions[randomQuestionIndex].correct + "-check").checked === true) {
    alert("Correct, such a Genius !");
    score = score + 1;
    QuestionReset();
    solvedQuestions = solvedQuestions + 1;
  } else {
    alert("Wrong mate, such a bad luck !");
    randomQuestionIndex = Math.floor(Math.random() * 6);
    QuestionReset();
    solvedQuestions = solvedQuestions + 1;



  }
  // End the Questions
  if (solvedQuestions >= 6) {
    window.location.href = "score.html";
    document.querySelector(".score-preview").textContent = score;
  }

});
<!DOCTYPE html>
<html>

<head>
  <title>Final Score !</title>
  <link href="https://necolas.github.io/normalize.css/7.0.0/normalize.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,800" rel="stylesheet">
  <link href="Styles/styles.css" type="text/css" rel="stylesheet">
  <link href="http://meyerweb.com/eric/tools/css/reset/reset.css" rel="stylesheet" type="text/css">


</head>

<body style="background-color: #09d0a4;">
  <div class="container clear">
    <div class="left-score">
      <h1 class="score-preview bold "><span class="score-bordar">0 | 6</span></h1>
      <h4 class="score-joke bold">Thanks for nothing</h4>
    </div>
    <div class="right-score">
      <h1 class="signature bold ">This was made with <br><br> <i class="fa fa-heart" aria-hidden="true"></i></h1>
      <div class="container-photos">
        <div class="photo-1"></div>
        <div class="photo-2"></div>
        <div class="photo-3"></div>

      </div>

    </div>



  </div>
</body>

</html>
<!-- HTML radio box code 


--!>


Show source
| javascript   | dom   | web   | frontend   | web-deployment   2017-10-04 22:10 0 Answers

Answers to Undefined global variables ( 0 )

Leave a reply to - Undefined global variables

◀ Go back