Operation Killdeer Javascript (Solved)

Here’s my code:

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

To bad I don’t know java…

seems fine to me? what goes wrong?

It says ran out of time

My hero immediately goes to the X, without doing the function of shouldRun

maybe try if shouldRun() == true

java and javascript are very different!

1 Like

Okay, i will

(20 chars)

Can anyone translate it to python?

def shouldRun():
    if hero.health < hero.maxHealth / 2:
        return True
    else:
        return False
while True:
    if shouldRun: #not sure if it's shouldRun() in java like python idk
        hero.moveXY(75, 37)
    else:
        enemy = hero.findNearestEnemy() #btw you should add if enemy
        hero.attack(enemy)

I think

Thank you. That will help.

Add parenthesis after this. Then translate to java so donut girl can see it in her language.

This should be if (shouldRun() == true) { because otherwise it’s not running the function. It’s like how in hero.findNearestEnemy(); you add parenthesis after hero.findNearestEnemy

1 Like

Thank you! I think i understand now.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.