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 Arrays Multidimensional Arrays Create a Multidimensional Array

Kord Monaco
Kord Monaco
3,442 Points

Console gives me an error at line 14: Cannot read property '0' of undefined at createListItems

const playlist = [
  ['So What', 'Miles Davis', '9:04']
  ['Respect', 'Aretha Franklin', '2:45'],
  ['What a Wonderful World', 'Louis Armstrong', '2:21'],
  ['At Last', 'Ella Fitzgerald', '4:18'],
  ['Three Little Birds', 'Bob Marley and the Wailers', '3:01'],
  ['The Way You Look Tonight', 'Frank Sinatra', '3:21']
];


function createListItems( arr ) {
  let items = '';
  for ( let i = 0; i < arr.length; i++ ) {
    items += `<li>${ arr[i][0] }, by ${ arr[i][1] } - ${ arr[i][2] }</li>`;
  }
  return items;
}

document.querySelector('main').innerHTML = `
  <ol>
    ${createListItems(playlist)}
  </ol>
`;

4 Answers

Kord Monaco
Kord Monaco
3,442 Points

Thank you for the help Cameron! I edited my previous comments to include the correct format for extra practice.

Kord Monaco
Kord Monaco
3,442 Points

I did not add a comma after the first array, which gave me an error on line 14. Don't you love debugging as a beginner?

const playlist = [
  ['So What', 'Miles Davis', '9:04'],    <---
  ['Respect', 'Aretha Franklin', '2:45'],
  ['What a Wonderful World', 'Louis Armstrong', '2:21'],
  ['At Last', 'Ella Fitzgerald', '4:18'],
  ['Three Little Birds', 'Bob Marley and the Wailers', '3:01'],
  ['The Way You Look Tonight', 'Frank Sinatra', '3:21']
];
Cameron Childres
Cameron Childres
11,817 Points

Glad you got it! That's a way too familiar pain.

Quick tip, use the "markdown cheatsheet" linked under the comment box to format your code next time for easier reading. Like this:

```javascript
code goes here
```

I made the same exact mistake in my code!! forgot that comma. ugh.

Me 3! It's because what we cut and pasted from the teacher's notes had an error.

Thanks - I had the exact same problem!