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 trial

JavaScript Object-Oriented JavaScript: Challenge Rendering the Game startGame() Method Solution

Stephen Garcia
seal-mask
.a{fill-rule:evenodd;}techdegree
Stephen Garcia
Python Development Techdegree Student 11,647 Points

Missing Token

I'm getting the board to show up but getting an error saying

Game.js:21 Uncaught TypeError: this.activePlayer.activeToken.drawHTMLToken is not a function at Game.startGame (Game.js:21) at HTMLButtonElement.<anonymous> (app.js:4) startGame @ Game.js:21 (anonymous) @ app.js:4

I double checked my code but can't figure out what's missing. Here's a link to my Github if anyone could help.

https://github.com/StephenDGarcia/Team_Treehouse_OOJS

1 Answer

Hi Stephen!

I checked your REPO, and your activePlayer method in your player.js file doesn't do anything:

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);
    }

    createTokens(num) {
        const tokens = [];

        for (let i = 0; i < num; i++) {
            let token = new Token(i, this);
            tokens.push(token);
        }

        return tokens;
    }

    unusedTokens() {
        return this.tokens.filter(token => !token.dropped);
    }

    activeToken() {
        return this.unusedTokens[0]; 
    }

    activePlayer() {
                                   // NO CODE - DOESN'T RETURN ANYTHING
    }
}

I hope that helps.

Stay safe and happy coding!