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!

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 trial

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

Paul Calabrese
Paul Calabrese
13,516 Points

My 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

Hi 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
Paul Calabrese
13,516 Points

I knew it was going to be something subtle like that. Thanks so much - headache gone.

You're very welcome! Happy Coding!