Leave It To Cleaver (Javascript)

Here’s my code:

function cleaveWhenClose(target) {
    if (hero.distanceTo(target) < 5) {
        if (hero.isReady("cleave")) {
            hero.cleave(target);
        }
    } else {
        hero.attack(target);
    }
}
while (true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        cleaveWhenClose(enemy);
    }
}

This is an easy level and I have done it before but I forgot-

@Hydrobolic? or someone??

My items:

It looks like the function’s if and else statements has mistakes.

Looks closer.

1 Like

Hmm I don’t see them ;(

It doesn’t matter with your items. Look:

The if and else statements do not match!

1 Like

So how do I fix these?

Well, match the if and else statements!

Send me your code now.

move the else down off the bracket im no expert at javascript but i think this is your error

@Vanessa, just indent the “else” by one tab space and youll be good. let me know if you need anything else and if that was the only problem, could you delete the code? otherwise other ppl would easily be able to copy it

1 Like

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