Distracting Dungeon (help me please)

Hi,
I have a problem with my code.
What’s wrong?
I don’t understand…
If you can explain me, it is very cool.

// Navigate the mountain maze with a peasant pal.
// Advanced while-loop usage is required!

function moveBothTo(point) {
    while(hero.distanceTo(point) > 1) {
        hero.move(point);
        hero.command(peasant, "move", point); 
    }
}

var peasant = hero.findNearest(hero.findFriends());
while(true) {
    // Command your friend to build a decoy towards x + 1:
    hero.command(peasant, "buildXY", "decoy", peasant.pos.x + 1, peasant.pos.y);
    var nextPoint = {x: hero.pos.x, y: hero.pos.y + 28};
    moveBothTo(nextPoint);
    // Create a new x/y object +28 units away in the x dir:
    nextPoint = {x: hero.pos.x + 28, y: hero.pos.y};
    // Find the nearest enemy:
    var enemy = hero.findNearestEnemy();
    // While there is an enemy:
    while (enemy) {
        // While the enemy's health is > 0:
        while (enemy.health > 0) {
            // Attack the enemy:
            hero.attack(enemy);
            // Update the variable to the next nearest enemy:
            enemy = hero.findNearestEnemy(); 
        }     
    }
    hero.say(peasant.distanceTo(nextPoint));
    moveBothTo(nextPoint);
}
```

One thing that I see is that you should redefine enemy outside the while loop that has the condition:
while (enemy.health > 0)

while(enemy.health > 0){
hero.attack(enemy);
}
enemy = hero.findNearestEnemy();