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.


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!