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 Two-Dimensional Arrays

Ben Ahlander
Ben Ahlander
7,528 Points

Why isn't this working?

var playList = [
  ["Yolo", "Ben Ahlander"],
  ["Bannana Pancakes", "Jack Johnson"],
  ["fdafdasf","fadfdasf"]
];

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

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

printList(playList);

Moderator Edit: Added Markdown to the post so the code is readable in the Community. Please refer to the Markdown Cheatsheet for the proper formatting before posting code in the Community.

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

your function is printSongs, but you call printList. also when it creates the html with the song and artist, you are adding the song twice and the artist not at all.

Tyler Nilsson
Tyler Nilsson
10,106 Points

Yeah james south hit the head of the error buddy.

Barry Harding
PLUS
Barry Harding
Courses Plus Student 1,711 Points

var playList = [ ["Yolo", "Ben Ahlander"], ["Bannana Pancakes", "Jack Johnson"], ["fdafdasf","fadfdasf"] ];

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

function printSongs( songs ) { var listHTML = '<ol>'; for ( var i = 0; i < songs.length; i += 1) { listHTML += '<li>'+songs[i].join(' by ','<br>')+ '</li>'; } listHTML += '</ol>'; print(listHTML); }

printSongs(playList);