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 trialTravis Barry
9,020 PointsQuiz works but having a problem with the display, not sure what is wrong
Hello, I was able to make the quizz fine but it keeps displaying in a strange way, the final print out is adding a blank list item after each answer in the correct and incorrect array, I'm not sure if it is just my browser or if it's something I actually did in the code. Is it showing up for everyone? And if it is, what part of the code is doing it?
var questions = [
[ "What number comes just before 1?", 0],
["What number is the lowest 3 didget number?", 100],
["Meaning of life?", 42]
]
var correctAnswers = 0;
var question;
var answer;
var response;
var HTML;
var correct = []
var incorrect = []
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 < questions.length; i += 1) {
question = questions[i][0];
answer = questions[i][1]
response = parseInt(prompt(question));
if (response === answer) {
correctAnswers += 1;
correct.push(question);
} else {
incorrect.push(question);
}
}
HTML ="You got " + correctAnswers + " answers right!";
HTML +='<h2>You got these questions correct:';
HTML += buildList(correct);
HTML +='<h2>You got these questions wrong<h2>'
HTML += buildList(incorrect);
print(HTML);
Thank you to everyone who contributes to answering my question :)
1 Answer
Steven Bister
12,011 PointsHi,
Looks like all you need to do is close your li tag here:
for (var i = 0; i < arr.length; i += 1) {
listHTML += '<li>' + arr[i] + '</li>';
}
I think that should sort your problem :)
Tobias Edwards
14,458 PointsTobias Edwards
14,458 PointsAlso, your missing a semi-colon after 'answer = questions[i][1]' :)