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

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1

Can 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) {

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('You answered  ' + correctAnswers + '  questions correctly!');


Please and thank you!


3 Answers

Anton Klyuchkovksiy
Anton Klyuchkovksiy
8,327 Points

Oh, 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()) {

This one is works.

Or you can edit your replies in "questions" array:

"python", "emmanuel macron", "ruby", "javascript"

No, I just changed it on workspace and still not keeping count.

Oh 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!