Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Help Needed with Lv. Munchkin Swarm (JavaScript)


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);


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


Where do I put this in?


@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?


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