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 trialLeonardo Motta
11,284 Pointsconfused with game.ready
in this project what the game means here? we are adding this if statement in the playToken() method which belongs to the game object. Is game.ready a reference to the game object ready property? why don't we use this.ready? How javaScript knows game.ready is a reference to the game's ready property?
if (targetSpace !== null) {
game.ready = false;
activeToken.drop(targetSpace);
}
Leonardo Motta
11,284 Pointsit was also not really clear for me, I tried to find definition for game but I did not find it, I am confused if it is a reference to the game object ready property (this.ready)
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Leonardo Motta ! Yes, game.ready
is a reference to the ready
property on an instance of the Game
class. The game
object was declared on line 1 of app.js
. That being said, I feel like you should be able to use this.ready
here.
Hope this helps!
Alexander Davison
65,469 PointsHow does the file containing game.ready = false;
access the game
variable from app.js
?
Jennifer Nordell
Treehouse TeacherAlexander Davison the app.js is linked in the index.html
. All those files before it are the set up of the classes, as you are well aware. But until the class that sort of kick starts this chain of events (the Game) object, is created nothing really happens. None of that code is executable by itself. It's all just in a state of waiting. The thing that sets this whole thing in motion is the creation of that instance of Game
The game then creates the players and board. The board creates the spaces and tokens. The reason it can read that game variable is because it is now in the global namespace and none of these are modules so they can see each other.
Dzmitry Aliakseichyk
12,290 PointsShe made a mistake, people make mistakes. If you open the Final Complete Project Game.js she added a line const game = this;
before game.ready.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsI read all of the code in that file, but I couldn't find any definitions of
game
. I am curious also :/Ashley Boucher Guil Hernandez