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 trialSwan The Human
Full Stack JavaScript Techdegree Student 19,338 PointsWhy 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
231,269 PointsThere 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.
Trevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 PointsTrevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 Pointsbecause the last check in the loop is x+3 which could then run to a max of 7 which is the amount of columns. Correct?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThe board only has 4 columns.