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!

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

JavaScript Object-Oriented JavaScript: Challenge Adding the Game Logic checkForWin() Method Challenge Solution

Swan The Human
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

Why is it this.board.rows -3?

I understand the if statement because it adds to the x or y axis by one to manually iterate through the spaces. but i'm not sure why in the for loop it says -3

1 Answer

Steven Parker
Steven Parker
225,664 Points

There are four separate tests combined together in the conditional expression, one of which looks 3 cells ahead (+3). So the loop must compensate by stopping 3 before the end (-3) to prevent trying to access cells beyond the range.