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

Munchkin Swarm JavaScript Problem!


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();
return this.attack("Chest");


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.


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.


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


i think so semi colon will not come after else ?


Not in javascript.

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


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: …


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


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


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


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.