[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);
}

1 Like

OMG Thank you SO MUCHHHH… I DID IT…

2 Likes

Good job Dude! :smiley:

1 Like

Hi! i can’t solve this.
(i do Python)
here’s my code!

You have one arrow. Make it count!

This should return the enemy with the most health.

def findStrongestEnemy(enemies):
strongest = None
strongestHealth = 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies:
while enemyIndex < len(enemies):
enemy = hero.findNearestEnemy()
# Set an enemy variable to enemies[enemyIndex]
enemy = enemies(enemyIndex)
# If enemy.health is greater than strongestHealth
if enemy.health > strongestHealth:

        # Set `strongest` to enemy
        # Set strongestHealth to enemy.health
        enemy = strongest
        enemy.health = strongestHealth
    # Increment enemyIndex
    enemyIndex += 1

return strongest

here’s my inventory, if it will help:

can you format your code properly press this image

how do you?
i don’t know what you mean?

I’ll do it for you

# You have one arrow. Make it count!

# This should return the enemy with the most health.

def findStrongestEnemy(enemies):
strongest = None
strongestHealth = 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies:
while enemyIndex < len(enemies):
enemy = hero.findNearestEnemy()
# Set an enemy variable to enemies[enemyIndex]
enemy = enemies(enemyIndex)
# If enemy.health is greater than strongestHealth
if enemy.health > strongestHealth:

        # Set `strongest` to enemy
        # Set strongestHealth to enemy.health
        enemy = strongest
        enemy.health = strongestHealth
    # Increment enemyIndex
    enemyIndex += 1

return strongest

thank you a lot!
thanks!

but it still says there is no enemyIndex.
but it still said enemyIndex = 0


see???
it does!

delete this 200000000

put this in the while loop by pressing tab and change the parentheses around enemyIndex to this [ and this]

thank you so much, but it still says there is no enemyIndex :hushed:

Please help me please😃

I’ve been stuck on this level for a day…
and i’m still coding!

flip these around 2000