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 trialNathan Angulo
4,565 PointscorrectAnswer not working?
So everything is seems to be working fine except my correctAnswer counter in the print message at the bottom of my funciton
var questions = [
['How many states in the U.S.?', 50],
['What\'s the name of your cat?', 'Caesar'],
['What is your name?', 'Nate']
];
var corectAnswer = 0;
var question;
var answer;
var response;
var html;
function print(message) {
document.write(message);
}
function Quiz (list) {
while (true) {
for (var i = 0; i < list.length; i += 1 ) {
response = prompt(list[i][0]);
answer = list[i][1];
response = response.toLowerCase();
}
if (response = 'quit') {
break;
}
else if (response === answer) {
correctAnswer += 1;
}
}
print('You got ' + corectAnswer + ' questions right');
}
Quiz(questions);
2 Answers
Matt Johnson
Courses Plus Student 2,735 PointsLooks like you're just missing the 'r' in the function. You have 'corectAnswer' as the variable, but in the IF statement you have 'correctAnswer'
Matt Johnson
Courses Plus Student 2,735 PointsTo have 'quit' work, you should have 2 or 3 '=' in order to compare the result 'response' to 'quit'. One '=' is an assignment.
Also, put your logical statement (if, else if) within the for loop. Since it is not within the loop now, it's not counting your responses. To get the counter to work, I removed one of the '=' from the comparison on the else if. The issue you'll run into now is that if you lowercase the response but not the answer, they won't compare to be equal.
Nathan Angulo
4,565 PointsNathan Angulo
4,565 Pointshaha! wow. I was going mad for the smallest fix. Thank you.
Nathan Angulo
4,565 PointsNathan Angulo
4,565 PointsSo I fixed the 'correctAnswer' to be spelled correctly everywhere... but I'm noticing that my 'quit' is no longer working... and the 'correctAnswer' counter still isn't working.