Shield Rush Problems in JavaScript


#1

I am stuck on Shield Rush level! Argh. I have read through everyone’s comments and I still can’t find a solution. Any help would be appreciated!
Here is my code:
if (this.isReady(“cleave”)) {
this.cleave(enemy);
this.shield();

}else {
this.attack(enemy);
}


#2

Welcome to the forums aubrey but PLEASE read the FAQ to format you code properly with triple backticks lick this is your code formatted properly

if (this.isReady("cleave")) {
this.cleave(enemy);
this.shield();

}else {
this.attack(enemy);
}

At first sight Im seeing the fact that you are not checking if an enemy is there before attacking use this

else if(enemy){
    this.attack(enemy);
}

(I am assuming that you declare var enemy)

and you are suppose to not use attack just shield and cleave so you code should be this

if (this.isReady("cleave")) {
this.cleave(enemy);


}else {
this.shield();
}

#3

with an “if(enemy)” of course

if (enemy && this.isReady("cleave")) {

#4

Thank you both! I figured it out-
loop {

var enemy = this.findNearestEnemy();
if (this.isReady("cleave")) {
 this.cleave(enemy);  

} else {
this.shield();
}