Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,660 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.