I need help on Operation Killdeer java script


#1

I need help on this level. Here is my code:

// Lure the ogres into a trap.
// But, they are careful.
// These ogres will only follow the hero if the hero is injured.
// This function checks the hero's health and returns a Boolean value.
function shouldRun() {
    if (hero.health < hero.maxHealth / 2) {
        return true;
    } else {
        return false;
    }
}

while (true) {
    // Run to the X only if the hero shouldRun().
    if shouldRun() {
        hero.moveXY(76, 37);   
        // Otherwise, fight!
    } else {
        enemy = hero.findNearestEnemy();
        hero.attack(enemy);    
}

#2

I just solved it. I didn’t put brackets on the start and end of shouldRun()


#3

I had the same problem and by reading this, I solved it. Thanks!


#4

Somehow this helped me, even though I just moved the enemy = hero.findNearestEnemy; inside the if/else concerning the attack.


#5

function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
var enemy = hero.findNearestEnemy();
if (enemy != “Heizenburg”) {
hero.attack(enemy); // Move to the X only if shouldRun() returns true
}
hero.moveXY(75, 37);
}


#6

Please learn to your code from the game from now on and use the </> button or it won’t format properly. When you click the </> button, the following will appear:
PostCode
There are many people here willing and able to help. If you use the </> button correctly, your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If it doesn’t look like the code above, you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you.

`


#7

I need help on ‘Operation Killdeer’ all the previous help dosen’t seem to work.

function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
if (shouldRun) {
hero.moveXY(76, 35);
} else {
enemy = hero.findNearestEnemy();
hero.attack(enemy);
}
}


#8

Please format your code properly:

For help @MunkeyShynes and @Chaboi_3000