[SOLVED] Javascript Code Question

Hi,

Trying to figure out what I’ve done wrong here. Trying to use this loop for Kithgard Brawl.

   while (true) {
var enemy = hero.findNearestEnemy();
if (hero.isReady("cleave")) {

    hero.cleave(enemy);
 }
   else {
    var enemy = hero.findNearestEnemy();

    hero.attack(enemy);
  }
}

Thanks!

1 Like

why are you defining enemy again, you don’t need to.

and you should surround this code with if(enemy) because sometimes you won’t be able to find an enemy

Why does it seem that indentation is wrong, the while at the top is indented, but the other lines and loops are not.

1 Like

indentation doesn’t matter in javascript, it only matters in python,

Thank you very much!

1 Like

you are welcome (Post must be at least 20 characters)

So as long as code is within brackets and such, indentation is not necessary, unless you want it to be organized.

it is not about brackets, it is about the language itself