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 trialNicholas Mudd
4,523 PointsConsole says 'Can't read property zero'
Hello, I've been following along on the JavaScript 'Two-Dimensional Arrays' video and I can't seem to display my text. After correcting some minor typos I've arrived at a problem I can't solve alone with the console. After opening the console, it says on line 17 that it "cannot read undefined property of '0'" although my line of code looks just like Dave's! Has Dave forsaken me? I must admit my grasp of JavaScript is tenuous at best and any help would be most appreciated. Thank you!
My JavaScript code in this exercise:
var playList = [ [ 'Lithium', 'Nirvana'], [ 'So Glad', 'Ariel Pink\'s Haunted Graffiti'], [ '...And the Rain', 'John Maus'], ['Blazing Arrow', 'Blackaliscious'] ['See Emily Play', 'Pink Floyd'], ['Respect', 'Notorious B.I.G'], ];
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);
2 Answers
Steven Parker
231,198 PointsYou just have a typo in your data (not the code).
You're missing a comma (,) between "'Blackaliscious']
" and "['See Emily Play'
".
Nicholas Mudd
4,523 PointsAha! I'll keep that in mind in the future when I see this message! Thank you Steven.
Cindy Lea
Courses Plus Student 6,497 PointsCindy Lea
Courses Plus Student 6,497 PointsCheck & make sure songs[i][0] has a zero in it & not the letter O