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

Remi Vledder
Remi Vledder
14,144 Points

Error "Player.js:33 Uncaught ReferenceError: tokens is not defined". (even in provided source code)

The problem occurs for me following the step of the teacher. But also even when I open the project files provided in the .zip at Stage 5 Step 9.

The error message I get is at the following line:

return tokens.filter(token => !token.dropped);
// Player.js:35 Uncaught ReferenceError: tokens is not defined
// at Player.get unusedTokens [as unusedTokens] (Player.js:35)

I guess the tokens should be coming from the function right before it, namely 'createTokens'. There everything seems to be in order and the code is just as provided by the teacher.

Anyone else running into this error?

Stu Finn
Stu Finn
3,427 Points

Looks like you're missing the 'this' keyword to reference the Player object:

return this.tokens.filter(token => !token.dropped);
Remi Vledder
Remi Vledder
14,144 Points

Thanks Stu Finn . It seems you had the answered first. However you answered it in a comment rather than a answer which doesn't allow me to mark it as answered question. So you're not getting points for this sadly. However, you do get the honor ;).

Stu Finn
Stu Finn
3,427 Points

Glad it worked!

Haha, it's all good. Cheers

1 Answer

You need to use 'this' because you need to refer to the Player object.

Remi Vledder
Remi Vledder
14,144 Points

Perfect. That works. So this seems to be a bug in the provided example source code by the teacher, since it isn't used there as well.

Adding it gives me another error though, but I'll post that in a follow-up question.

Cheers