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 2

Nicholas Wallen
Nicholas Wallen
12,278 Points

I copied his code exactly but no prompt pops up when I run it.

//two dimensional array

var questions = [ ['How old is Steve?', 27], ['How old is Trevor?', 29], ['How old is the baby?', 0] ];

//variable to hold how many correct answers var correctAnswers = 0; //random question variable var question; //random answer variable var answer; //random response variable var response; //random html variable var html;

//function to print the dialogue to the screen function print(message) { document.write(message); }

//for loop that cycles through each iteration in the array based upon the arrays length for ( var i = 0; i < questions.length; i += 1) { //question is grabbing the first column in the array question = questions[i][0]; //answer is grabbing the second column in the array answer = questions[i][1]; //response holds the users answer and parses it to make it an integer response = parseInt(prompt(question)); if (response === answer { correctAnswers += 1; }


html = "You got " + correctAnswers + " question(s) right."; print(html);

2 Answers

Hi Nicholas, it is quite hard to read your code like that. I would suggest you have a look a the Markdown Cheatsheet. It shows you how you can convert simple text to HTML. Neverthelesss, try this code this should help you:).

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) {

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

html = "You got " + correctAnswers + " question(s) right."
Steven Parker
Steven Parker
224,924 Points

It's very difficult to tell the code from the comments without formatting, but it looks like there's a missing closing parenthesis after the word "answer" in this part:

  if (response === answer { correctAnswers += 1; }

In future questions, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.