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 triallydialavecchia
3,826 PointslistHTML does not get printed
HI guys,
I am struggliging with this 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);
It seems that it does not print any html on my page. on the console I can't see any error message.
Is the syntax wrong? Thanks!
3 Answers
Jennifer Nordell
Treehouse TeacherIt's not the code. If I take your code and link it in to an html file it runs fine and displays the list on the page in an ordered list. So let's check some basics. Are you doing this in workspaces? Make sure you've saved your file and then preview it again and then refresh the browser. If this still doesn't work, try clearing your browser cache. Hope you get this fixed!
lydialavecchia
3,826 PointsThaks Jennifer, It was my workspace that was not working properly!
Adarsh Prabhu
15,394 PointsMy code does not work, although it is almost exactly in the format above
var theList = ['Goonies', 'Godfather', 'Conversation'];
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(theList);
Jennifer Nordell
Treehouse TeacherHi Adarsh Prabhu! Well first, this probably should have been posted as an additional question. But the reason yours won't print is that you have a syntax error on this line:
listHTML += '<li>' + <list[i]> + '</li>';
If I change it to this, it runs:
listHTML += '<li>' + list[i] + '</li>';
The angle brackets are not needed around your reference to your array.