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

[Solved] Mountain-mercenaries _in javascript,


why !!!

why the blue orges are so powerful!

why my soldiers all died !!!

is there a problem with my code ?


loop {

var coin=this.findNearest(this.findItems());
if (coin) {   
    this.move(coin.pos);       }

if ( > this.costOf("soldier")) {

var enemy = this.findNearest(this.findEnemies());
if (enemy) {

    var soldiers = this.findFriends();
    var soldierIndex = 0;
    while (soldierIndex<soldiers.length) {
         var soldier = soldiers[soldierIndex];
        this.command(soldier, "attack", enemy);



Merged Doublepost

i added "this.attack(enemy) "in the while-loop,

though i passed the level;

but i don’t think i made it right…


You might want to make the soldiers attack their nearest enemy, i.e.

var enemy = soldier.findNearestEnemy()
if (enemy) this.command(soldier, 'attack', enemy)

(Also, >= this.costOf('soldier') also works (note the >=)


Can’t figure this level out, my soldiers won’t move at all. Can someone please help?


Please post your code( formatted properly ) onto your post and explain what you’ve already tried what’s happening in more detail and any other things that happened when you ran the program e.g. errors or freezing so that people can help you.
Thank you


I already figured it out, but Thanks! :slight_smile: @Deadpool198