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 trialPaul Calabrese
13,516 PointsMy code is not tracking the correct answers, help please!
I can't seem to really wrap my head around whats wrong with this one. I tried really hard to get it 100% correct on my own and got pretty close, but I was not able to get the correct var to store and alert the amount of answers that were correct. I even followed through the solution video a number of times with this one to see whats wrong with it, but it still returns 0 right every time!
1 Answer
Marcus Parsons
15,719 PointsHi Paul,
You just had an error in your answer
variable in the for loop. You put [i,1] instead of [i][1] like so:
for (var i = 0; i < questions.length; i += 1) {
question = questions[i][0];
//changed to questions[i][1] correct notation
answer = questions[i][1];
response = parseInt(prompt(question));
if (response === answer) {
correct += 1;
}
}
Paul Calabrese
13,516 PointsPaul Calabrese
13,516 PointsI knew it was going to be something subtle like that. Thanks so much - headache gone.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou're very welcome! Happy Coding!