Hello,
I’ve been stuck on this level for a while now, and it seems that the archers are attacking the ogres first instead of the enemy with the highest health. Everything else works fine, though.
My code:
function findStrongestEnemy(enemies){
var enemyIndex = 0;
var strongest = null;
var strongestHealth = 0;
while (enemyIndex < enemies.length){
var enemy = enemies[enemyIndex];
if (enemy.health > strongestHealth){
strongest = enemy;
strongestHealth = enemy.health;
}
enemyIndex++;
}
return strongest;
}
var enemies = hero.findEnemies();
var target = findStrongestEnemy(enemies);
var freinds = hero.findFriends();
var freindIndex = 0;
var attackers = freinds[freindIndex];
if (target){
freindIndex++;
hero.command(attackers, "attack", target);
}
The problem is that two yetis make it out in the end.