function findStrongestEnemy(enemies) {
var strongest = null;
var strongestHealth = 0;
var enemyIndex = 0;
while (enemyIndex < enemies.length) {
if (enemies[enemyIndex].health > strongestHealth) {
strongest = enemies[enemyIndex];
strongestHealth = strongest.health;
enemyIndex += 1;
}
}
return strongest;
}
var enemies = hero.findEnemies();
if (enemies) {
hero.say(findStrongestEnemy(enemies));
}
I cannot work out what I am doing wrong! My hero just says the name of the first ogre rather than the one with the most health. I’m sure I’m missing something very simple but I cannot see what it is! Any help would be much appreciated, thanks.