Help Needed with Lv. Munchkin Swarm (JavaScript)


#1

Hello, I have had great difficulties completing the level “Munckin Swarm” using JavaScript. Here is my code:
while(true) {

(4 spaces) var enemy = hero.findNearestEnemy();
(4 spaces) if (enemy) {
(8 spaces) var distance = hero.findNearestEnemy();
(8 spaces) if (distance < 10) {
(12 spaces) hero.cleave(enemy);
}
(8 spaces) else {
(12 spaces) hero.attack(“Chest”);
}
}
(4 spaces) else {
(8 spaces) hero.attack(“Chest”);
}
}

If you could help me find the problem, it would me much appreciated. Thanks!

-This issue has been solved. Line 6 must be changed to
(8 spaces) var distance = hero.distanceTo(enemy);


#2

Problem is here:
var distance = hero.findNearestEnemy();


#3

Where do I put this in?


#4

@garrbear I believe what @juraj_pechac is saying is "are you sure you want to calculate the distance with the function hero.findNearestEnemy(); " ?

Do you know of another function that the hero has that can calculate the distance?


#5

Oh, yes, looking back on my code today I realize I put hero.findNearestEnemy(); instead of hero.distanceTo(enemy); Thank you so much!