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 trialIvana Lescesen
19,442 PointsCan someone help me ?
What is wrong with my code? Thank you so much :)
var correctAnswer = 0;
var questions = [
['what is the capital of sweden', 'stokholm'],
['What is my favorite TV show', 'COMMUNITY'],
['What is my favorite movie', 'Love Actually'],
];
var answer;
function print(message) {
document.write(message);
}
function askQuestions( quiz ) {
for ( var i = 0; i < quiz.length; i += 1) {
answer = prompt(quiz[i][0]);
answer = answer.toLowerCase();
if (answer == quiz[i][1]){
correctAnswer+=1;
print( 'That is correct ');
} else {
print( 'sorry ');
}
}
}
askQuestions(questions);
document.write("<p>You got " + correctAnswer + " out of 3 questions correct.</p>")
Moderator Edited: Added Markdown to the code block so it is readable in the forum. Please refer to the Markdown cheatsheet for formatting instructions. <code> elements don't work with Markdown.
1 Answer
Steven Parker
231,269 PointsYou didn't describe your problem, but I do notice one functional issue:
It looks like you're converting the user's answer to lower case, but then comparing it to stored answers which contain upper case characters. Only answers stored as lower case can match a correct answer.
Happy coding! -sp
Steven Parker
231,269 PointsSteven Parker
231,269 Pointsmessage is a function argument. Those don't need to be defined.