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 trialJulianna Kahn
20,702 PointsI don't really understand this chunk of code.
moveRight(columns) { if (this.columnLocation < columns - 1) { this.htmlToken.style.left = this.offsetLeft + 76; this.columnLocation +=1; } } I see that columns is a property in the Board class but I don't understand where it gets defined in Token, Also, I don't see where htmlToken gets associated with x and y values such that the column location can be offset on the x-axis.
2 Answers
Steven Parker
231,261 PointsIn this method, "columns" is a parameter name and not related to the property in the "Board" class. It get's its value from the argument passed when "moveRight" gets called elsewhere in the code.
The token's "x" location is stored in the "offsetLeft" property, and "y" isn't being used here.
Update: All the "htmlToken" method does is return a reference to the HTML element that provides the visual image of the token. The element has style properties that are used for positioning, and the "left" property is being adjusted by this method ("moveRight").
Julianna Kahn
20,702 PointsYou're saying that the columns parameter being passed, has nothing to do with columns defined in the Board constructor.
I understand that there is no "y" coordinate. But I am still uncertain of where the htmlToken() method gets the data it needs to define the token location/coordinates on the board.
Thanks
Julianna Kahn
20,702 PointsSo we have a reference to the visual image of the token. My understanding is that .offset - 76 means the token would be physically positioned 76 pixels to the left, along the x axis. But what/where is the code that defines the original positioning of the token?
Steven Parker
231,261 PointsSteven Parker
231,261 PointsThe properties of "htmlToken" (including "offsetLeft") are established by the browser when the element is created.
When tokens are created (in "drawHTMLToken"), they are placed inside the div with the ID of "game-board-underlay", initially at the left side by default.
Julianna Kahn
20,702 PointsJulianna Kahn
20,702 PointsSo, if I correctly understand, the initial x-value for the token location is defined to exist in the first column, all the way at the left of the board. That helps a lot because I couldn't see how we knew where it was before it was first moved. Thanks.