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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

Amber Hicks
Amber Hicks
4,500 Points

Why is the HTML for the array with the wrong questions indented?

I've gone over and over the code but I can't figure out why the heading and ordered list of wrong items is being indented. My code is below:

var quiz = [ ["What number does four score represent?", "80"], ["What is the meaning of life?", 42], ["How many in a dozen?", "12"] ];

function quizBowl( questions ) {

var answer; var correct = []; var wrong = []; var html; var score = 0;

for (var i = 0; i < questions.length; i++){
  answer = prompt(questions[i][0]);

 if (answer === questions[i][1])
 {  
  correct.push(questions[i][0]);
  score += 1;
 }
  else {
  wrong.push(questions[i][0]);
  }
}

html = "<h2>You got " + score + " right!</h2>"; html += "<h3>You got these question(s) correct:</h3> <ol> <li>" + correct.join('</li><li>') + "</li></<ol>"; html += "<h3>You got these question(s) wrong:</h3> <ol> <li>" + wrong.join('</li><li>') + "</li></<ol>";

print(html); }

quizBowl(quiz);

1 Answer

Steven Parker
Steven Parker
229,732 Points

That's because the list above it has not been closed.

There's a stray "<" symbol in this string: "</li></<ol>". This causes the closing tag of the ol list to be ignored.

Also, I noticed that the answer to the second question isn't enclosed in quotes, so it won't ever match the input. There's some other minor issues but with this fixed I'll bet you can work them out.