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
Rod R
3,050 PointsPlaylist has 12 items
My playlist has 12 items and every other item is blank. Whats wrong with my code?
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);
1 Answer
David Evans
10,490 PointsHi Rod,
You have two opening <li> tags when you're forming your list. Make sure to change the 2nd one to </li> to close each list item properly.
I have marked the line with a <----
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++) {
listHTML += "<li>" + list[i] + "</li>"; <------
}
listHTML += "</ol>";
print(listHTML);
}
printList(playList);
Rod R
3,050 Pointsthanks
Rod R
3,050 PointsRod R
3,050 Pointsfound it: ...</li> (instead of <li> x 2)... needed to close the list item tag