Kelvintaph Crusader help me please

Hello,
My hero survive, but my friends don’t survive. I don’t know why.
Can you help me please ?

Here my code :

var friends = hero.findFriends();

for(var i = 0 ; i < friends.length ; i++){
    var friend = friends[i];
    var witch = friend.findNearest(hero.findByType("witch"));
    if(friend.type == "paladin"){
        if (witch) {
            hero.command(friend, "attack", witch); 
        }
        else{
            var target = friend.findNearestEnemy();
            if (target) {
                hero.command(friend, "attack", target);
            
            }
        }
    }
}

while (hero.pos.x < 69) {
    hero.move({'x':69, 'y':15});
} 

hero.say("Hi!");

while (hero.pos.x < 37) {
    hero.move({'x':37, 'y':16});
}
hero.say("Bye!");

for(var a = 0; a < 3 ; a++){
    var enemy = hero.findNearest(hero.findByType("catapult"));
    if (enemy) {
        hero.attack(enemy);
    }
    hero.say("Hi!");
    
    while (hero.pos.x > 37) {
        hero.move({'x':37, 'y':16});
    }
    
    while (hero.pos.x < 78) {
        hero.move({'x':78, 'y':14});
    }
}

Your strategy is wrong. You should first focus the fire from the archers and the attacks from the paladin on the witch, while letting the soldiers hold off the rest of the ogres. You can also command the Paladin to cast heal on the soldiers if they get low on health. After the witch is taken care of, focus the fire of the archers on one target, so you can eliminate them faster and decrease the amount of damage they do.