Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Borrowed Sword Help

I am stuck on this level. Everything works correctly, but my archers do not kill the last two enemies. There are no errors, but my archers did not survive so I can not complete the level. Could someone please help me achieve this?

function findStrongest(){
    var enemies = hero.findEnemies();  
    var strongestBoi = null; 
    var health = 0;   
    for(var i = 0; i < enemies.length; i ++) {
        var enemy = enemies[i]; 
        if(enemy.health >= health) {
            strongestBoi = enemy;
            health = enemy.health; 
        }
    }
    return strongestBoi;
}

 while (true){
    var buddies = hero.findFriends();
    for (var b=0; b < buddies.length; b++){
        var buddy = buddies[b];
        var target = findStrongest();
        hero.command(buddy, "attack", target);
    }
}

To focus your fire on one target, you need to make sure that all of your archers are firing at just one target. Currently with your code, they could potentially be firing at different targets.

What minor change could you make for all of your buddies to fire on just one target?