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

David Loder
David Loder
4,901 Points

I have the code written as shown but cannot get it displayed onto the page. Can anyone debug for me?

This should be the code. Is there anything I'm missing? I need a second pair of eyes. var playLists = [ ['I Did It My Way', 'Frank Sinatra'], ['Respect', 'Aretha Franklin'], ['Imagine', 'John Lennon'], ['Born to Run', 'Bruce Springsteen'], ['Louie Louie', 'The Kingsmen'], ['Maybellene', '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); }


2 Answers

If you run it through the console you'll see:

Uncaught ReferenceError: playList is not defined



should be

David Loder
David Loder
4,901 Points

Thanks Kris. I would have never caught that.

I'm using Atom for my text editor. On the last segment, I had a similar error. My code wouldn't run because one of the many "playLists" variables was missing a capital L.

In Atom, when you click on one variable, it highlights all uses of the same variable.

I got the error in the console, but couldn't find it in my code. That's how I discovered the clicking on one and seeing all of the uses thang.

Hope that helps in the future!