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 trialLinus Johansson
12,469 PointsToken not defined error in player class
// this is the player class who creates an instance of the Token class
class Player {
constructor(name, id, color, active = false) {
this.name = name;
this.id = id;
this.color = color;
this.active = active;
this.tokens = this.createTokens(21);
}
/**
* Creates token objects for player
* @param {integer} num - Number of token objects to be created
* @return {array} tokens - an arary of new token objects
*/
createTokens(num) {
const tokens = [];
for (let i = 0; i < num; i++) {
let token = new Token(i, this);
tokens.push(token);
}
return tokens;
}
}
1 Answer
Dwayne Bynum
10,408 PointsI noticed that I had to switch the script tag with the attribute ''src = token.js" above the tag with the "src = player.js". I figured that the token class neeeded to be created before referencing it inside player.js.
Linus Johansson
12,469 PointsLinus Johansson
12,469 Pointsthis is the token class itself
class Token{ constructor(i,owner){ this.id =
token-${i}-${owner.id}
; this.owner = owner; this.dropped = false; }}