Friend and Foe

A brawl in the woods! Pick out friend from foe and prepare for a battle.

https://codecombat.com/play/level/friend-and-foe

Solution

// Peasants and peons are gathering in the forest.
// Command the peasants to battle and the peons to go away!

while(true) {
    var friend = hero.findNearestFriend();
    if(friend) {
        hero.say("To battle, " + friend.id + "!");
    }
    // Now find the nearest enemy and tell them to go away.
    var enemy = hero.findNearestEnemy();
    if(enemy)
    {
        hero.say("go away, " + enemy.id + "!");
    }    
}
Points for
damage-dealt
Needed items with
findNearestEnemy
This site is in another language version