Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
See the solution for the createTokens() method assignment.
JS Documentation
To read more about how to document your JS code, visit usejsdoc.org and devdocs.io/jsdoc.
Code Documentation Correction
The project files are correct, but there's a small error in what you see on screen.
The documentation for this method is missing the @param information. The complete documentation should look like this:
/**
* Creates token objects for player
* @param {integer} num - Number of token objects to be created
* @return {array} tokens - an array of new token objects
*/
Solution Code
Player class constructor
method:
constructor(name, id, color, active = false) {
this.name = name;
this.id = id;
this.color = color;
this.active = active;
this.tokens = this.createTokens(21);
}
Player class createTokens()
method:
/**
* 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;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up