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 trialNicholas 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
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
231,269 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.