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 trialpeichunliu
33,154 PointsWhy don't the right and wrong lists print?
I can't find errors in my codes, did I miss something? Please help me, thanks.
var quizList = [
["What the color is made from mixing red and yellow?", "orange"],
["What the color is made from mixing blue and red?", "purple"],
["What the color is made from mixing yellow and blue?", "green"]
];
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
var correct = [];
var wrong = [];
function print(message) {
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = message;
}
function buildList(arr) {
var listHTML = "<ol>";
for (var i = 0; i < arr.legnth; i++ ) {
listHTML += "<li>" + arr[i] + "</li>";
}
listHTML += "</ol>";
return listHTML;
}
for ( var i = 0; i < quizList.length; i++) {
question = quizList[i][0];
answer = quizList[i][1];
response = prompt(question).toLowerCase();
if ( response === answer ){
correctAnswers += 1;
correct.push(question);
} else {
wrong.push(question);
}
}
html = "You get " + correctAnswers + " question(s) right.";
html += "<h2>You got these questions correct:</h2>";
html += buildList(correct);
html += "<h2>You got these questions wrong:</h2>";
html += buildList(wrong);
print(html);
1 Answer
Stephan Olsen
6,650 PointsIn the for loop in the buildList function, you misspelled length.
peichunliu
33,154 Pointspeichunliu
33,154 PointsThanks so much for your help! It drove me crazy :)