Munchkin Swarm JavaScript Problem!


#1

Helo, i have a problem with Munchkin Swarm.
this is my code:
Error is "Unchreachable ‘while’ after return.
I’dont know where i can write ‘return’ on this code.
pls help, im stuck wink

loop; {
var enemy = this.findNearestEnemy();
var distance = this.distanceTo(enemy);
if (distance < 10 && this.isReady("cleave")) {
return this.cleave();
}
else;
{
return this.attack("Chest");
}
}

#2

What language are you using because thats not javascript or python.

If it’s javascript, one of your problems is you have a semi-colon after loop and else. semi colon is not used like this. There should be nothing after those except the curly braces. if it’s python you need that semi-colon to be a regular colon : and you need to get rid of the curly braces and properly indent your lines.


#3

Also, you don’t need the:

All you need is the distance < 10, because on this level, the enemies won’t attack you unless cleave is ready (it’s just the way the level is :smile: ) . If you don’t want to do this, it should still work, but do what sotonin said.


#4

Also, don’t use return; your code will stop running if you do that.


#5

i think so semi colon will not come after else ?


#6

Not in javascript.

if (something > something2) {
    // do something
} else {
    // do something else
}

#7

yes, but rishiloyola98245 might be using Python, in which case, I’m pretty you need a colon, like this : <-------.
In other words, code should look like this:
else: …


#8

yeah @abducktion (else : ) will come but he wrote (else ; ) i think so that will not work .


#9

munchkin swarm is the hardest and most ‘hard to understand’ level for me in all of the levels in code combat


#10

Really? I think it is quite simple. If the enemies are far enough away, loot the chest. Otherwise, you kill them with cleave.


#11

Yeah… i don’t remember it being particularly difficult. Beat it on the first try. But everybody has different skill / experience levels, so it’s probably not unusual for some people to struggle with it. As long as you learn from it and improve, it’s working.