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 trialCaleb Newell
12,562 PointsHow do I set Space object’s token property to the Token object?
In the challenge, It wants me to set the Space object’s token property to the Token object passed to the method. But I think I might be overthinking it.
here is my code.
mark(token) {
this.token = token;
}
(and a link to the challenge https://teamtreehouse.com/library/objectoriented-javascript-challenge/adding-the-game-logic/build-the-mark-method)
1 Answer
devcollin
7,489 PointsYes, that's correct.
this.token
is the Space object's token property, which you see in the Space constructor method. Then you're setting it to token
, which is the argument that holds the Token object passed to the method.
For clarity, this could also be written with token
being renamed to anything else. For example:
mark(argument) {
this.token = argument;
}
argument
can be named anything and becomes whatever is passed to the mark
method when we call it (though we haven't done that yet). In this case, our argument is going to be a Token object, so we name it token
.