Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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])
  score += 1;
  else {

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


1 Answer

Steven Parker
Steven Parker
216,136 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.