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

My quiz only show the first question wrong/right, but does not display the rest.

I'm working on the quiz.js file. As far as I can tell I followed pretty much the same method as described in the quiz challenge solution. Any help is appreciated!

Forgot to link my workspace. Here it is:

https://w.trhou.se/druejhdxx5

1 Answer

You should move the line with the closing </ol> tag and your return statement outside your for loop. The return statement in the loop breaks the execution which is why you only see one line for arrays with data. With an empty array there is no return statement which is why you see undefined.

function buildList(arr){
  var listHTML = '<ol>'

  for ( var i = 0; i < arr.length; i += 1){
   listHTML += '<li>' + arr[i] + '</li>';
  }
  listHTML += '</ol>';
  return listHTML;
 }

Thanks Kris. That makes sense.