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

[SOLVED] Brittle Morale

function findStrongestEnemy(enemies) {
    var strongest = null;
    var strongestHealth = 0;
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
         strongest = enemy;
         strongestHealth = enemy.health;
        enemyIndex+=1;
    }
        return strongest;
}
var enemies = hero.findEnemies();
var leader = findStrongestEnemy(enemies);
if (leader) {
    hero.say(leader);
}

Please help I am very stuck on it. (This is JavaScript)

Howdy and welcome to the forum!

Looks like you removed all of the comments too soon…you are missing a needed statement, based on:

        // If enemy.health is greater than strongestHealth

While I would recommend just Restarting the level, here’s the default code, in case it helps:

// You have one arrow. Make it count!

// This should return the enemy with the most health.
function findStrongestEnemy(enemies) {
    var strongest = null;
    var strongestHealth = 0;
    var enemyIndex = 0;
    // While enemyIndex is less than the length of enemies:
    
        // Set an enemy variable to enemies[enemyIndex]
        
        // If enemy.health is greater than strongestHealth
        
            // Set `strongest` to enemy
            // Set strongestHealth to enemy.health
            
        // Increment enemyIndex
        
        
    return strongest;
}

var enemies = hero.findEnemies();
var leader = findStrongestEnemy(enemies);
if (leader) {
    hero.say(leader);
}

OMG Thank you SO MUCHHHH… I DID IT…

1 Like

Good job Dude! :smiley: