Help on game dev 2 agony of defeat

I need help on Agony of Defeat. Here is my code:

game.spawnPlayerXY("captain", 40, 35)

def onSpawn(event):
    while True:
        unit =
        enemy = unit.findNearestEnemy()
        if enemy:

# When a unit is defeated, spawn a gold coin.
def onDefeat(event):
    unit =
    # Set x to unit.pos.x, plus a random number between -5 and 5
    x = unit.pos.x + game.randomInteger(-5, 5)
    # Set y to unit.pos.y, plus a random number between -5 and 5
    x2 = unit.pos.y + game.randomInteger(-5, 5)
    # Spawn a "gold-coin" at x, y
    game.spawnXY("gold-coin", x, x2)

game.setActionFor("munchkin", "spawn", onSpawn)
game.setActionFor("munchkin", "defeat", onDefeat)

spawnTime = 0
while True:
    if game.time > spawnTime:
        x = game.randomInteger(10, 70)
        y = game.randomInteger(10, 60)
        game.spawnXY("munchkin", x, y)
        spawnTime = game.time + game.randomInteger(1,4)

When I click “play” it just says “Fix You Code”.

Could you send me a link?

Sure. Here: CodeCombat - Coding games to learn Python and JavaScript

Can you send me a screenshot of the error?

Add your player stats after you spawn the player.

player.maxHealth = 
player.maxSpeed = 
player.attackDamage = 

Then assign each one a value so that you can complete the level by defeating ogres and collecting items.