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 Making the Game Interactive moveLeft() and moveRight() Methods Solution

Uncaught TypeError: this.activePlayer.activeToken.moveRight is not a function at Game.handleKeydown

Everything goes ok until a press the left arrow and then an uncaught typeError appears: Game.js:57 Uncaught TypeError: this.activePlayer.activeToken.moveRight is not a function at Game.handleKeydown (Game.js:57) at HTMLDocument.<anonymous> (app.js:15) I don't know why it fives me this error. Can anyone help please?

3 Answers

Steven Parker
Steven Parker
220,634 Points

A common generic cause of this error is trying to access an attribute/method on a null or undefined variable. Check the value of "activePlayer" or "activePlayer.activeToken".

If you'd like more specific help, make a snapshot of your workspace and post the link to it here.

Thanks Steven, I'll take a look and get it working. :)

In my case I got this error because I forgot to save the Token.js file before I ran the code - so literally that function didn't exist! Duh! Took me a couple minutes to figure out why that wasn't working.