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 Game Logic Methods Solution

Richard Preske
PLUS
Richard Preske
Courses Plus Student 4,356 Points

checkForWin() not a function in Game.js line 80 and token only drops one space one player only

https://w.trhou.se/mc0puklbg0

Token only drops one space left right moves OK. checkForWin is not a function error after dropping a token. Thanks for any help.

1 Answer

Steven Parker
Steven Parker
231,271 Points

The message is accurate, there is no "checkForWin" function in Game.js.

But there seems to be one in Space.js, was it added to the wrong file?

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

checkForWin() is function in Space.js and checkForWin is called in Game.js line 80. The devtools are saying in updateGameState the function checkForWin is not a function.

Steven Parker
Steven Parker
231,271 Points

But the code in Game.js calls this.checkForWin(). The "this" means "in this same class", which means "Game" and it's not there!

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

Thanks, should be in Game.js checkForWin that is. But not sure why my token doesn't fall to bottom open space. It only drops one space. Also getting maximum call stack exceeded in space.js get owner method.

Steven Parker
Steven Parker
231,271 Points

In Game.js on line 79, "mark" is being passed the target instead of the token. See if you can continue the debugging from there (hint: "player" is not an array).

If your original question has been answered, any additional issues should get a fresh question.