JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

Gafur Iusupaliev
Gafur Iusupaliev
3,090 Points

Why doesn't this code work? It prompts the questions, but everything after the for loop does not work.

Here's the code:

var correctAnswers; var incorrectAnswers; var quiz = [ ['question', 'answer'], ['question?', 'answer'], ['best twitch emote?', 'Kappa'], ['best TTV emote?', 'OMEGALUL'] ];

for(i = 0; quiz.length > 0; i += 1) { var response = prompt(quiz[i][0]); if(response.toLowerCase === quiz[i][1].toLowerCase) { correctAnswers += 1; } else { incorrectAnswers += 1; }

}

document.write("You answered " + correctAnswers + "questions correctly"); document.write("You answered " + incorrectAnswers + "questions incorrectly");

That code is formatted with markdown. Click the Markdown Cheatsheet link right above the post answer button below.

2 Answers

You have two issues. The condition to run in your for loop should be:

for(i = 0; i < quiz.length; i += 1) {

quiz.length > 0 would create an infinite loop.

Second, toLowerCase should be followed by parentheses: toLowerCase()

Gafur Iusupaliev
Gafur Iusupaliev
3,090 Points

omg, i'm actually braindead, lol, I accidentally entered 0 insted of an "i", and thanks for pointing out the parenthesis, and how did you make your message look like an actual workspace, with the background and everything highlighted as needed

Gafur Iusupaliev
Gafur Iusupaliev
3,090 Points

Thanks again, sorry for the bad formatting