[SOLVED] Javascript Code Question


#1

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!


#2

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


#3

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


#4

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


#5

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


#6

Thank you very much!


#7

#8

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


#9

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


#10

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