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

It doesent give me ordered list.......

PLz help meh it doesn't say anything on the console but doesn't write an ordered list either. plz help me my stuff here It should give me an ordered list?

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

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

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

    }
listHTML += "</ol>"
print(listHTML);

}

print(playList);

Steven Parker
Steven Parker
221,291 Points

When posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

2 Answers

Steve Mustanski
Steve Mustanski
15,081 Points

It's a little hard to read in the post, but I think the first issue is that the writeList function is never called against the playlist to generate the HTML output. Try changing the last print(playList) call to writeList(playList).

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

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

function writeList(list) {
  var listHTML = "<ol>";
  for (var i = 0; i < list.length; i++) {
    listHTML += "<li>" + list[i] + "</li>";
  }

  listHTML += "</ol>";
  print(listHTML);
}

writeList(playList);
James Estrada
seal-mask
.a{fill-rule:evenodd;}techdegree
James Estrada
Full Stack JavaScript Techdegree Student 25,862 Points

The fix that @Steve Mustanski provided you should give you the ordered list. Note that when speaking of an ordered list given by the <ol> tag, it means a list of items preceded by an ordered numeric or alphabetic identifier, not the list itself.