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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Nicholas Wallen](https://secure.gravatar.com/avatar/05ef5337a0dcd24e5acf273a6f84afa4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Nicholas Wallen
12,278 PointsI 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
![tobiastrinkler](https://secure.gravatar.com/avatar/a511cbb45fcbe181efc0a091935e6895?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
tobiastrinkler
Full Stack JavaScript Techdegree Student 16,538 PointsHi 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) {
document.write(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."
print(html);```
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsIt'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.
Or watch this video on code formatting.