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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Brad Horvath](https://secure.gravatar.com/avatar/1b3e075cf78b31f623aef01886574830?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Brad Horvath
3,845 PointsNeed help with quiz challenge
var quiz = [
["How presidents have there been?",44],
["How many states are there?",50],
["How many stripes are on the American Flag?",13]
];
var correctQuestions = [
];
var incorrectQuestions = [
];
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
function print(message) {
var outputDIV = document.getElementById("output");
outputDIV.innerHTML = message;
}
function buildList(arr) {
var listHTML = "<ol>";
for (var i = 0; i < arr.length; i += 1) {
listHTML += "<li>" + arr[i] + "</li>"
}
listHTML = "</ol>";
return listHTML;
}
for (var i = 0; i < quiz.length; i += 1) {
question = quiz[i][0];
answer = quiz[i][1];
response = prompt(question);
response = parseInt(response);
if (response === answer) {
correctAnswers += 1;
correctQuestions.push(question);
} else {
incorrectQuestions.push(question);
}
}
html = "You got " + correctAnswers + " question(s) right.";
html += "<h2>You got these questions correct:</h2>";
html += buildList(correctQuestions);
html += "<h2>You got these questions wrong:</h2>"
html += buildList(incorrectQuestions);
print(html);
I am doing the js quiz challenge and I am experiencing some problems. If someone could help me, that would be great. We need to prompt some questions and then see if they are correct. I have that done correctly expect it asks each question twice. Also, I need to have the questions answered correctly appear in a certain area and the questions answered incorrectly appear in a different area. If someone can help me, that would be great.
2 Answers
![Ryan Field](https://uploads.teamtreehouse.com/production/profile-photos/2892162/micro_ryan3.jpg)
Ryan Field
Courses Plus Student 21,242 PointsHi, Brad. I tested your code in the browser console, and it works fine for me. The only thing is that you have
listHTML = "</ol>";
inside your buildList
function, but it should be this:
listHTML += "</ol>";
so it's overwriting the variable instead of concatenating.
![Brad Horvath](https://secure.gravatar.com/avatar/1b3e075cf78b31f623aef01886574830?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Brad Horvath
3,845 PointsYes. You were correct. Just a typo. Thanks for your help