Unit 3, Lesson 22 - student game has an error


My student created a game that works like the old Frogger game. When he runs the game, he gets an error. I have looked over this code and can’t figure out why the error occurs.
Here is a link to his project:

You move the frog using the error keys. You are supposed to avoid the space ships and move the frog all the way to the top of the screen. When you collide with a ship, the lives go down and the frog is placed at the starting point.

The error happens when the frog hits the first ship.
ERROR: Line: 116: TypeError: frog.isTouching is not a function

All the other code using the frog sprite seems to work. I couldn’t see any reason why the frog.isTouching call would not work. In the end, I deleted the entire function that he was using and created a new one. I put the same code in the new function and it worked.
Can anyone see an error in this student’s code?



Hi Kammie,

isTouching is a method/function that is automatically there for any sprite. If frog.isTouching isn’t a function, that means that frog isn’t a sprite anymore. I’d have the student check over the code for somewhere that the frog variable was assigned something that is not a sprite, probably because the student meant to assign something to a sprite property, but instead assigned the value to the entire sprite, thus knocking the sprite out of the variable and leaving a new (non-sprite) value there instead.

You could also use watchers to “watch” frog. Eventually, it will change from a sprite to something else, and you’l know when the problem shows up.