Game Dev 2 6. JailBreak

I been trying to get my hero to find the nearest enemy to defeat it but it keep saying “line 7; Type Error: cannot read property “target” of undefined.”

// The player only needs to defeat some of the enemies.
game.spawnHeroXY(“goliath”, 62, 25);

// Use game.addDefeatGoal(X) to allow the player to win
// after defeating X enemies! (In this case, X should be 4)
var hero =; (this is line 7)
var enemy = hero.findNearestEnemy;
if (enemy)

What is And where has the game spawned any heroes?
Also, in Game Dev you don’t need to program the hero. Just click for the hero to move to someplace/attack an ogre.