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 enemy.health is greater than strongestHealth
if(enemy.health > strongestHealth){
// Set `strongest` to enemy
strongest = enemy;
// Set strongestHealth to enemy.health
strongestHealth = enemy.health;
enemyIndex++;
}
return strongest;
}
}
It kills the leader then the hero remains stationary and dies
Hi @skjdklsa8iyh, welcome to the forum!
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.
Danny
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?
Danny
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
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 .
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…