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 trialNathan Strauman
6,003 PointsScript not working
Can anyone tell me why this isn't working?
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);
4 Answers
samiff
31,206 PointsThat code works for me, how have you added it to your html document? What isn't working for you?
Nathan Strauman
6,003 Pointssamiff
31,206 PointsI just forked your workspace and it works fine for me with all six items displayed. Have you tried opening the preview URL in a private browsing window or another web browser? Might just be something funky going on with cached data.
Nathan Strauman
6,003 Pointssigh... :-)
That worked! Thank you!
Bryan Woodard
5,757 PointsYea the same thing was happening to me. My code seldom run from the workspace, but that same code always works when I download the project files and run them in my own editor and browser window.
Nathan Strauman
6,003 PointsNathan Strauman
6,003 Points<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Musical Playlist</title> <link rel="stylesheet" href="css/styles.css"> </head> <body> <h1>My Music Playlist</h1> <script src="js/playlist.js"></script> </body> </html>
Nathan Strauman
6,003 PointsNathan Strauman
6,003 PointsHTML looks fine. When I hit preview out of Workspaces, I only get "My Music Playlist" on top with nothing else under it.
samiff
31,206 Pointssamiff
31,206 PointsAre you able to snapshot your workspace so it's easier to see what's going on? It's in the top right corner when you have the workspace open.