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!

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 2 Solution

Travis Barry
Travis Barry
9,020 Points

Quiz 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');

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;
  } else {

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);

Thank you to everyone who contributes to answering my question :)

Tobias Edwards
Tobias Edwards
14,458 Points

Also, your missing a semi-colon after 'answer = questions[i][1]' :)

1 Answer

Steven Bister
Steven Bister
12,011 Points


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 :)