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)
game.addDefeatGoal(4);
var hero = hero.target; (this is line 7)
var enemy = hero.findNearestEnemy;
if (enemy)
hero.attackEnemy();

What is hero.target? 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.