Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript: Challenge Adding the Game Logic Build the updateGameState() Method

Akshay Alok
Akshay Alok
7,857 Points

How is checkTokens different from the getter method unusedTokens?

I just wanted to know if there is something I am missing... Because I don't really see how making a new function checkTokens() would add any functionality.

Akshay Alok
Akshay Alok
7,857 Points

We are calling unusedTokens inside the method after all... So is there perhaps a use case where having made this function would have benefitted us?

1 Answer

Harald N
Harald N
15,831 Points

Hi Akshay Alok. If I do understand your question correctly, I get your confusion. I was also confused about this first.

This is a getter method and not a function:

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

it returns a list item containing all the unused tokens.

This is a method:

    checkTokens() {
        if (this.unusedTokens.length > 0) {
            return true;
        } else {
            return false;
        }
    }

It acts like a regular function witch you can call upon. This function will returns a boolean.

Since the getter method returns us the list item, we use it in our method to check if the list length.

It was not a good explanation, but I hope you get it a bit more now :) If it helped, mark this as solved.