I need help with Leave it to Cleaver

This is my code:

‘’’’// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called target
function cleaveWhenClose(target) {
if(hero.distanceTo(target) < 5) {
// Put your attack code here
// If cleave is ready, then cleave target
var ready = hero.isReady(“cleave”);
hero.cleave(enemy);
// else, just attack target!
else {
hero.attack(enemy);
}
}
}

// This code is not part of the function.
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
// Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy);
}
}’’’’

im using java script

im sorry if its messy i dont know how to use the format thing

You use the format thing like this:

  1. Put three backticks (they’re underneath the Esc button)
  2. Place your code there.
  3. Put three more backticks.

Or you can press this button

1 Like
function cleaveWhenClose (target) {
    if (hero.distanceTo(target) < 5) {
        let ready = hero.isReady(“cleave”);
        hero.cleave(enemy);
        else hero.attack(enemy);
    }
}
while (true) {
    let enemy = hero.findNearestEnemy();
    if (enemy) cleaveWhenClose(enemy);
}

formatted properly, adjusted the 'var’s to 'let’s, and made it a bit easier to read C:

Anyway, @Tiny-saurus_REX, your error is that you assign hero.isReady(something) to a variable instead of doing something like:

if (hero.isReady(something)) doSomething();

Hey there @Tiny-saurus_REX! Please review this topic to learn how to post your code properly! We can’t help you if your code looks that way. ):