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 trialSchweine FEin
2,671 PointsWhy not just use join method?
While I watched the video I thought it would be easier if you just use the join method. In this Data-structure it's pretty easy and in my eyes even cleaner than using string concatenation.
listHTML += '<li>' + list[i].join( ' by ') + '</li>';
vs.
listHTML += '<li>' + list[i][0] + ' by ' + list[i][1] + '</li>';
What do you think about this?
john larson
16,594 Pointslooks innovative to me :D
john larson
16,594 Pointslooks innovative to me :D
john larson
16,594 PointsI also noticed if in the line for the "li", songs[i] seems to work just fine instead of songs[i][0]. Although as noted by Brett, that would change accessibility.
2 Answers
Marcus Parsons
15,719 PointsHey Luca,
Your code is cleaner than the code in the video (and a great use of that method), but this video has a very specific purpose. Up until this point, two dimensional arrays haven't been discussed. The point of this video is to go over how to access values within two dimensional arrays. For this specific case, join()
works but there are lots of other times where you need to know how to access the information in a two dimensional array and that's why Dave uses the code he does.
Schweine FEin
2,671 PointsWell perhaps the problem is I already knew what 2d arrays are and how I access them... From the perspective of someone who doesn't know this it makes of cause much more sense ... :p
Marcus Parsons
15,719 PointsAbsolutely right, Luca! :) If you wanna see something I've been working on that uses 2d and 3d arrays, check out my Tic Tac Toe game. Go into the source of the program and scroll down and you'll see all of the JavaScript for the game. I put a fair amount of comments in there so far. The computer will attempt to thwart you from winning, but I still have some fine tuning to do. And it doesn't look the greatest just yet lol :D
Brett Comardelle
8,541 PointsAlso, if you need to access the index of a student and their third score, you need two indexes: the student row and the third column. So, you would need to access the specific index. IE
recentGrade = students[rowIndex][columnIndex];
Brett Comardelle
8,541 PointsBrett Comardelle
8,541 PointsAlso, if you need to access the index of a student and their third score, you need two indexes: the student row and the third column. So, you would need to access the specific index. IE
recentGrade = students[rowIndex][columnIndex];