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 trial

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

Sarah Jee Watson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Jee Watson
UX Design Techdegree Graduate 28,197 Points

It looks ok, but nothing pops up in preview?

var correctAnswer = 0;

var quiz = [
['What is 1+1?', '2'],
['Which city has the largest population?', 'Toyko'],
['Who is the godfather of soul?', 'James Brown']
];


function print(message) {
  document.write(message);
}

for (i=0; i < quiz.length; i++) {

    var guess = prompt (quiz[i][0]);

    if (guess.toLowerCase() === quiz[i][1]) {
      correctAnswer += 1; 
  } else {
    alert('Wrong answer!');
  }

}

print('You got ' + correctAnswer + ' questions right!');

1 Answer

you forgot to init the var i in your for loop:

for(var i =0; i < quiz.length; i++){
//code for loop here
}