0

I have this quiz I am trying to make. I want it so it generates a random question.

I have

var quiz = [{
  "question": "Question 1: Who is Megatron", // Question 1
  "choices": [
    "Brandon Marshall",
    "Larry Fitzgerald",
    "Robert Griffin III",
    "Calvin Johnson"
  ],
  "correct": "Calvin Johnson"

}, {
  "question": "Question 2: Which player has won the most Superbowls", // Question 2
  "choices": [
    "Eli Manning",
    "Peyton Manning",
    "Aaron Rodgers",
    "Tom Brady"
  ],
  "correct": "Tom Brady"

}, ];

and I have

var randomNumber =Math.floor(Math.random()*3);
var currentQuestion = (randomNumber);

if(currentQuestion < quiz.length - 1){
    currentQuestion(randomNumber);
    questionsDone++;
    loadQuestion();
} else {
    showFinalResults();
}

After I freshly reload the page, the question is random. After I answer that question, a another random question doesn't appear. I want it so it generates a random number. every time I hit answer a question and use the randomly generated number as the question number.

Preston S
  • 2,751
  • 24
  • 37
Phil
  • 1

1 Answers1

0

When you load the next question your calling a function called currentQuestion that does not exist.

        //if we're not on last question, increase question number
            if(currentQuestion < quiz.length - 1){
                currentQuestion(Math.random()*4);
                questionsDone++;
                loadQuestion();
            }

What you will want to do is set currentQuestion

        //if we're not on last question, increase question number
            if(currentQuestion < quiz.length - 1){
                currentQuestion = Math.random()*4;
                questionsDone++;
                loadQuestion();
            }