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 Adding Data to Arrays

James Barrett
James Barrett
13,253 Points

List items not showing, no idea why!

Code:

HTML:

<!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>
<div id="listDiv">

</div>
<script src="js/helpers.js"></script>
<script src="js/playlist.js"></script>
</body>
</html>

JS helpers:

function printList( list ) {
  var listHTML = '<ol>';
  for (var i = 0; i < list.length; i += 1) {
    listHTML += '<li>' + list[i] + '</li>';
  }
  listHTML += '</ol>';
  print(listHTML);
}

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

JS playlist

var playList = [];
playList.push('I did it my way');
playList.push('Respect', 'Imagine');
playList.unshift('Born to Run');
playList.unshift('James, 'Barrett');

printList(playList);

All that shows is the heading: My music playlist... I have followed the code exactly... No idea why it is not showing, any suggestions?

Thanks, James.

2 Answers

It's a minor mistake on playlist.js file. Just put the missing quote after the "James" on playList.unshift('James, 'Barrett'); and then it will work. You can always use the javascript console (ctrl+shift+j) to find possible errors of your javascript code.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Try changing i +=1 to i++ in your for loop declaration.

There's something the JS syntax highlighting doesn't like in the code.

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