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

Nikola Jankovic
Nikola Jankovic
10,793 Points

[SOLVED] Why with my for loop NaN apires?

var questions= [
  ['Koliko Nikola Ima godina?', 26],
  ['Koliko Svetlana ima godina?', 27],
  ['Koliko je 2+2?', 4]

var answer;
var ask;
var correctAnswer;

var correct= 0;
var wrong= 0;

function print (message) {

for (var i=0; i<questions.length; i+=1) {
  answer= questions[i][1];
  ask= prompt(questions[i][0]);
  ask= parseInt(ask);
  if (ask=== answer) {
    correctAnswer+= 1;

print ('You have '+correctAnswer+' correct answers!');

Hi Nikola,

Glad you figured it out on your own.

It could be helpful to other students if you post your solution to the problem as an answer here.

For the time being, I'll update the title to indicate that it's solved.

1 Answer

Nikola Jankovic
Nikola Jankovic
10,793 Points

* appear- Sorry for the spelling mistake. This variable need to have value 0 var correctAnswer= 0; and when we run the loop we ad +1 every time the answer is correct.

marked as Best Answer

Thanks for coming back and leaving your solution.