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 trialRoderick Hung
Front End Web Development Techdegree Graduate 23,182 PointsExplain for loop in playToken().
How does the for loop set the target space to the last empty space in the column.
1 Answer
Jesse Ward
14,882 PointsI realized it's been awhile since the question was asked, but for anyone else:
They don't all become the target space. As the for loop iterates through the column, it sets targetSpace to the current space in the iteration. In other words, since the targetSpace variable is declared with 'let', each time the for loop runs it replaces the variable with the new iteration. Furthermore, it only replaces the declaration if the space is not null. That means that when the loop is finished, the last space in the column (the bottom space) that is not null will be the value of the the targetSpace variable.
Roderick Hung
Front End Web Development Techdegree Graduate 23,182 PointsRoderick Hung
Front End Web Development Techdegree Graduate 23,182 PointsIf all empty spaces become targetSpace then how does the token know where to drop?