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


Getting questions in a two-dimensional array to pop up with the prompt method.

I am trying to do a code challenge for creating a quiz with a two-dimensional array but can't get my code to show questions using the prompt method. The code I have written is: In the two-dimensional array part of the course, I cannot get the questions to pop up in the browser. The code that I have written is this: var questions = [ ['How many states are in the United States?', 50] ['How many continents are there?', 7] ['How many legs does an insect have?', 6] ]; var correctAnswers = 0; var question; var answer; var response; var html; function print(message) { document.write(message); }

for (var i = 0; i < questions.length; i += 1){ question = questions[i][0]; answer = questions[i][1]; response = parseInt(prompt(question)); }

1 Answer

Jason Cook
Jason Cook
11,403 Points

It appears that the only bug causing the problem is that you forgot to include a comma after each element of your array. Make the following change to your array declaration.

var questions = [ 
  ['How many states are in the United States?', 50], 
  ['How many continents are there?', 7],
  ['How many legs does an insect have?', 6],

That's the only change I made to your code, and then it worked correctly, providing the prompt for each question. I hope this helps.

Happy coding!