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

Pontus Bolmér
Pontus Bolmér
12,471 Points

I only get one number

I only get 1 undefined to list on the page, i cant find the problem. What is it i am missing?

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

Thomas Pans
Thomas Pans
9,428 Points

I see one semicolon which is not supposed to be there.

for ( var i=0; i < list.length; i += 1);

Also try to wrap your code in three backticks so it is easier for everybody to read and answer your questions. Now your code is very difficult to read and maybe i didn't spot all the errors.

Happy Learning ;)

Stefan Cutajar
Stefan Cutajar
7,747 Points

also you forgot to close the ol tag which I think is causing your program to break ... istHTML += "</ol"; print(listHTML);