Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGafur Iusupaliev
3,090 PointsWhy 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");
2 Answers
KRIS NIKOLAISEN
54,971 PointsYou 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
3,090 Pointsomg, 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
3,090 PointsThanks again, sorry for the bad formatting
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsThat code is formatted with markdown. Click the Markdown Cheatsheet link right above the post answer button below.