Help! level Sarven Outpost

hi this above all greetings to everyone, I’m learning to program new javascript I get stuck at the level Sarven Outpost

If someone takes pity and gives me a few tips that I have to do because when I attack no longer return to the path of movement and I think I have to do a circular motion.

Hola si alguien habla español seria genial para mi…

Could you post your code? It would be more effective if we can see it.

ok my code

// Ogres are attacking a nearby outpost!
// Command the hero to defend the tiny settlement.
// Time your patrol with a watch so no ogres can get through.

while(true) {
var polarPos = hero.now() / 5;
var xPos = 40 + Math.cos(polarPos) * 20; // Number between 20 and 60.
var yPos = 34 + Math.sin(polarPos) * 20; // Number between 14 and 54.
hero.moveXY(xPos, yPos);
// Check for ogres and defeat them!
// Make sure to attack the ogres while their health is above 0.
var enemy = this.findNearestEnemy();
var distance = this.distanceTo(enemy);
while(enemy ){
hero.attack(enemy);
//enemy = false;
}
}

Hola Isaac y bienvenidos al discurso. Por favor, recuerde que formatear el código de acuerdo con las preguntas más frecuentes.

Look at that line. You attack the enemy while it exists, but even if it’s dead - it exists.

Try this

while(enemy && enemy.health > 0){

And remove var distance = this.distanceTo(enemy);

Probe logic you sent me and work with some small changes
Thank you

Yep, it was not only one problem in the solution :wink: But I was sure that you would find other ones.