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
Adam Maley
5,946 PointsStill says 0 correct at end of quiz?
var questions = [ ["What color is an Apple", "Red"], ["What color is an Blueberry", "Blue"], ["What color is an Pumpkin", "Orange"] ]; var correctAnswer = 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)); if (response === answer) { correctAnswer += 1; } }
html= "You got " + correctAnswer + " question(s) right."; print(html);
Adam Beer
11,314 Pointsvar questions = [
["What color is an Apple", "Red"],
["What color is an Blueberry", "Blue"],
["What color is an Pumpkin", "Orange"]
];
var correctAnswer = 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));
if (response === answer) {
correctAnswer += 1;
}
}
html= "You got " + correctAnswer + " question(s) right.";
print(html);
Adam Maley
5,946 Pointsvar questions = [ ["What color is an Apple", "Red"], ["What color is an Blueberry", "Blue"], ["What color is an Pumpkin", "Orange"] ]; var correctAnswer = 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)); if (response === answer) { correctAnswer += 1; } }
html= "You got " + correctAnswer + " question(s) right."; print(html);
1 Answer
Antti Lylander
9,686 PointsThe problem is here:
response = parseInt(prompt(question));
You are givin a string (e.g. Red) as an answer. Now, parseInt will parse an integer out of it. Remove parseInt and it works. Though you might need some improvement still. Like put all your answers in CAPITAL letters in the questions array. Then use toUpperCase() on your prompt. Note it has different syntax than parseInt: string.toUpperCase()
Adam Beer
11,314 PointsAdam Beer
11,314 PointsHi Adam!
Code
Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.