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

I did it like this

var quiz = [["What is my name?", "George", ""], ["What is my wife name?", "Dina", ""], ["What is my son name?", "Chris",""], ["What is my father name?","Emil",""], ["What is mother name?","Aida",""] ]; var correctAnswers = 0; var html = ""; var html2 = "";

html = "<ol>"; html2 = "<ol>";

for (i = 0; i < quiz.length ; i++){ quiz[i][2] = prompt (quiz[i][0]); if (quiz[i][1].toLowerCase() === quiz[i][2].toLowerCase()){ html += "<li>" + quiz[i][0] + "</li>" correctAnswers += 1; }else{ html2 += "<li>" + quiz[i][0] + "</li>" }; }

html += "</ol>"; html2 += "</ol>";

document.write("<h3>You got " + correctAnswers + " question(s) right</h3>");

document.write("<h2>You Got these question(s) correct:</h2><br>"); print(html);

document.write("<h2>You Got these question(s) not correct:</h2><br>"); print(html2);

function print(message) { document.write(message); }

1 Answer

var quiz = [["What is my name?", "George", ""], ["What is my wife name?", "Dina", ""], ["What is my son name?", "Chris",""], ["What is my father name?","Emil",""], ["What is mother name?","Aida",""] ]; 
var correctAnswers = 0; 
var html = "<ol>"; 
var html2 = "<ol>";

for (i = 0; i < quiz.length ; i++){ 
    quiz[i][2] = prompt (quiz[i][0]); 
    if (quiz[i][1].toLowerCase() === quiz[i][2].toLowerCase()){ 
        html += "<li>" + quiz[i][0] + "</li>"; //semicolon missing
        correctAnswers += 1; 
    }else{ 
        html2 += "<li>" + quiz[i][0] + "</li>"; //also missing
    } 
}

html += "</ol>"; 
html2 += "</ol>";

document.write("<h3>You got " + correctAnswers + " question(s) right</h3>");

document.write("<h2>You Got these question(s) correct:</h2><br>"); 
print(html);

document.write("<h2>You Got these question(s) not correct:</h2><br>"); 
print(html2);

function print(message) { document.write(message); }

Use "" on one line before you enter a code in the forum, and another "" again on a single line after the code so that the snippet is more readable. Now your code has typos: missing semicolons and I think a { bracket. Don't try to write everything at once - write test write test so that you can find your mistake. Test your code in a real environment to see the errors. I did not mess up the code much but in the beginning, you declare a variable and its empty, on the next two lines you give them values, there is no point in that. :)