Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.