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 Object-Oriented JavaScript: Challenge Making the Game Interactive moveLeft() and moveRight() Methods Solution

A bit of logic

I wrote down the part that says if Column Location is less than the total columns - 1

But the thing is that the Columnlocation is 0 right or if it's not 0

but less than columns -1

I can understand that the last columns should be the final array [-1]

But I understand how the columns argument can access that information if it's not defined with the total amount of columns....

1 Answer

Steven Parker
Steven Parker
220,634 Points

I believe you're referring to the point about 3 minutes into the video where we hear that "Our columnLocation counter starts at 0 instead of 1, which is why we're checking that the column location is less than the total number of columns minus 1."

This is not a suggestion that the index will ever be negative (it will not), but that the index of each item is less than the number of the item you would get by starting a count at 1. And, the very last item has an index number that is one less than the total count. So if you had 4 columns, the index number of the last one would be 3.