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
Aimee Knight
9,701 PointsProgramming Step-by-Step: OO JS (Part 1) Question
At about 18 minutes in, Randy inspects the 2D spaces array which shows 8 elements for the x value, and 6 for the y value. I'm a bit confused because Randy mentions the 8th x-value element as being the array's length property. I was thinking though, that the 8th element was actually the 7th iteration of x, since the for loop is adding values to index 1-7 and skipping index 0? In my mind I pictured the following for spaces[1] iteration.
[ [undefined], [1,1], [1,2], [1,3], [1,4], [1,5], [1,6], [1,7] ]
If anyone can clarify this for me that would be wonderful!
4 Answers
Federico Giust
8,157 PointsHi Aimee,
Your first element 'undefined' is also counted as an element. This one has index 0, in objects and arrays the index starts from 0. So for example when you say the first element, in this case would be index 0 [undefined].
Fede
Aimee Knight
9,701 PointsYes Federico, that's exactly what I was trying to express above. :)
Randy Hoyt
Treehouse Guest TeacherOh, I think you're right. Good catch! I'll see what I can do to get that fixed.
Aimee Knight
9,701 PointsThank you for the assurance Randy. I'm fairly new, and I wanted to draw out the code on paper before the video implemented the CSS. When I started to draw everything out and match it against the video I started second guessing myself. Thank you so much for the great PHP, and now JS content!