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 Using For Loops with Arrays

followed along in the video and typed the code he typed. do i have a syntax error?

var playList = [
  'I Did It My Way',
  'Respect',
  'Imagine',
  'Born to Run',
  'Louie Louie',
  'Maybellene'
];

function print(message) {
  document.write(message);
}

function printList ( list ){
  var listHTML = '<ol>';
  for ( var i = 0; i < list.length; i +=1) {
    listHTML += '<li>' + list[i] + '</li>';

    listHTML += '<ol>';
    print(listHTML);

    printList(playList);

  }

Thats my code. When I previewed, the songs did not appear.

Ken Alger
Ken Alger
Treehouse Teacher

Edited for formatting.

You need to change listHTML += '<ol>'; to listHTML += '</ol>';

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! No, you do not have a syntax error. In fact, it's perfectly valid JavaScript, but it will not have the results you are after. You are trying to call the printList function from within the printList function, which is valid, but not what we're after in this case.

Move this line:

 printList(playList);

below the last closing curly brace and give it a go!

Hope this helps! :sparkles:

You need to change listHTML += '<ol>'; to listHTML += '</ol>';