Brittle Morale (JavaScript)

function findStrongestEnemy(enemies) {

var strongest = null;
var strongestHealth = 0;
var enemyIndex = 0;

// While enemyIndex is less than the length of enemies:

while(enemyIndex < enemies.length){
    // Set an enemy variable to enemies[enemyIndex]

    var enemy = enemies[enemyIndex];

    // If is greater than strongestHealth

    if( > strongestHealth){

        // Set `strongest` to enemy
        strongest = enemy;

        // Set strongestHealth to
        strongestHealth =;
    return strongest;


It kills the leader then the hero remains stationary and dies

Hi @skjdklsa8iyh, welcome to the forum! :tada:
If the arrow actually kills the leader then you don’t have anything to worry about. After the leader dies all the other ogres run away.
Have you made sure you call the function in a variable and hero.say() it?
Please could you post a screenshot of this.

Hmm. That’s odd. Your code (that I made sure was the same as the screenshot) works. I have a few questions:
Does the hero say an ogre name?
Is it the name of the strongest enemy? (click on the ogres to see their strength).
If so, what happens next? Does the archer not do anything?

Yeah, he says “Polifemo” and the archer shoots them to which they then remain stationary as the rest of them charge forward-- Upon clicking the corpse of the ogre they have -8547 health

Hi skjdklsa8iyh,

Your brackets aren’t quite right!


should be:



um im pretty sure that ++ is += but in javascript += is python

Both ++ and += work in JS. Only += works in Python.

but deadpool said += is only for python and ++ is only for javascript…

Umm, @Deadpool198 definitely knows more about programming than I do. But I tried out += and ++ in Python and JS before my last reply. Suggest you do the same - it’s the best way to find out for yourself :smiley:.


1 Like

Did I? My bad, I’m not sure whether I said += was only for python, but I would recommend using ++ in javascript considering it’s so neat!
You have to be able to have += for adding values above 1, ++ is literally the embodiment of “incrementation”, that is to say, increasing something by 1. You can also use -=, *= and /= I think. It’s just a contraction of var something = something * something else, and can be use with any operator.
Anyway, sorry for any confusion caused…