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

None of the JavaScript is running for this exercise, any ideas where I've gone wrong please?

var playList = [
  ['I did it my way','Frank Sinatra'],
  ['respect', 'Aretha'],
  ['Iamgine', 'John Lennon'],
  ['Born to run','Bruce'],
  ['Louie Louie', 'The Kingsmen'],
  ['Mabellene','Chuck Berry']
];

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][1] '</li>';
  }
  listHTML += '</ol>';
  print(listHTML);
}

printSongs(playList);
Daniel Rotenberg
Daniel Rotenberg
8,646 Points

Hi Kirk,

It looks like you had quotes around songs[i][0] and songs[i][1] which were unnecessary. Doing so would not print the array item you were trying to print. You also had an extra quote string that was not closed.

Try the code below, and if it works, compare it to your own.

var playList = [ ['I did it my way','Frank Sinatra'], ['respect', 'Aretha'], ['Imagine', 'John Lennon'], ['Born to run','Bruce'], ['Louie Louie', 'The Kingsmen'], ['Mabellene','Chuck Berry'] ];

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

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

Regards, Dan

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

Within the for loop of the printSongs() function there is a syntax error -- near the end of the line there is a + missing before the closing li tag.

Something else which may cause an error is on the same line, right before there the above should be placed, there is space between songs and the array notation -- "songs< SHOULD BE NO SPACE HERE >[i][1]"

Thanks Sean, that was it.