Help! level Sarven Outpost


#1

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…


#2

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


#3

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;
}
}


#4

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


#5

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);


#6

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


#7

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