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 trialAndrew Cauthorn
8,940 PointsQuestions answered always equals zero.
I basically followed along the video to complete this challenge, but I still can't get it to work. Any help is appreciated. :)
var questions = [
['MJ championships?', '6'],
['Lillard"s number?', '0'],
['Elliot Smith Albums Number?', '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));
if (response === answer) {
correctAnswers += 1;
}
}
HTML = "you got " + correctAnswers + " question(s) right.";
print(HTML);
2 Answers
Armin Kadic
16,242 PointsLooks like you missed a few small but important details. First detail is that you made the answers (numbers) in the "questions" variable to strings. Remove the quotes on the numbers, because otherwise the loop won't count it. Second one you wrote a comma (,) after your last array question-answer on line 4, remove it since there is no array following it. Third and last I believe is that you wrote on the last two lines "HTML" in caps lock while the variable name is "html", since javascript is case-sensitive, this isn't a good idea. If this helps you resolve your question, mark this answer as "best answer". :)
Good luck!
Andrew Cauthorn
8,940 PointsWow. I can't believe I missed those three things. Thanks for the assistance!