Help with dust, desert (JS)

Hi,

I just got stuck on the dust level.
I’m supposed to hit enemies 10x, but after one hit my hero plainly walks off to the ambush point.

var hits = 0;
var enemy = this.findNearestEnemy();  
while (hits <= 10) {
     this.attack(enemy);
     hits += 1;
     }

// When you're done, retreat to the ambush point.
this.moveXY(79, 33);

What am i doing wrong? Am i not breaking the while-loop correctly?
Except for the amount of hits, the code is right. How should i fix my hit count?

Thanks

Maybe pull the findNearestEnemy() inside the while-loop.
Other than that, our code is identical.

3 Likes

I’ll try that, thanks!

Edit: That was indeed the solution. Thanks for helping me out ^^

I followed the code given here and fixed the findNearestEnemy, but i’m getting this error.

Your problem is that you use a variable before you declare it.
You say

while ("something you don't know yet" <= 10) {
    //Do not assign strings, this is an example!
    var "Now I Tell You What Im Speaking About" = 0;    
    
    //rest of code
}

You should move the var hits = 0 in front of the while. Also you don’t want to set hits = 0 ever iteration. You won’t make any progress then.