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 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,843 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.