Having trouble with Brittle Morale


#1

I am having troubles with Brittle Morale. Even though I use a function to return the enemy with the highest health and say this enemy’s name, causing the archer to shoot the leader, the level does not succeed.

My code is as follows:

// You have one arrow. Make it count!

// This should return the enemy with the most health.


function findStrongestEnemy(enemies) {

    // sorts enemies array descending by enemy health property
    enemies.sort(function(a,b){ 
    b.health - a.health;
    });

    // return Trogdor in sim (with 575 health), or whoever has most health
    return enemies[0]; 
}

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

#2

Are you sure about return? :wink:


#3

Oh wow, I can’t believe I missed that one.


#4

Maybe it’s a habit with arrow functions

enemies.sort((e1, e2) => e2.health - e1.health);

I usually prefer to use ES6 in web dev practices.