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 trialSolace Enwere
15,102 PointsCan someone please tell me why the correctAnswers count is not working in this code??
var quizList = [
['What is a programming language that is also a snake?', 'Python'],
['Who is the president of France?', 'Emmanuel Macron'],
['Which progeamming language is also a gem?', 'Ruby'],
['Which progamming language I\'m I learning right now?', 'JavaScript']
];
var correctAnswers = 0;
var ask;
function print(message) {
document.write(message);
}
function answerQuiz ( questions ) {
listHTML = '<ol>'
for (var i = 0; i < questions.length; i++) {
ask = prompt(questions[i][0]);
ask = ask.toLowerCase();
if (ask === questions[i][1]) {
correctAnswers ++;
}
listHTML += '<li>' + questions[i][0] + ' <strong>' + questions[i][1] + '</strong>'
}
listHTML += '</ol>'
print(listHTML);
print('You answered ' + correctAnswers + ' questions correctly!');
}
answerQuiz(quizList);
Please and thank you!
3 Answers
Anton Klyuchkovksiy
8,327 PointsOh, I get it :) You compare user input in lower case with answers, which are not.
ask = prompt(questions[i][0]);
ask = ask.toLowerCase();
if (ask === questions[i][1].toLowerCase()) {
correctAnswers++;
}
This one is works.
Or you can edit your replies in "questions" array:
"python", "emmanuel macron", "ruby", "javascript"
Solace Enwere
15,102 PointsNo, I just changed it on workspace and still not keeping count.
Solace Enwere
15,102 PointsOh I see! thanks! It works great! I didn't realize I had turn both of them to to lower case for it to match up.
Thanks Anton!