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

Weakest Quickest(Level Help)

// Defeat shamans to survive.

// This function finds the weakest enemy.
function findWeakestEnemy() {
    var enemies = hero.findEnemies();
    var weakest = null;
    var leastHealth = 99999;
    var enemyIndex = 0;
    // Loop through enemies:
    while ( < leastHealth) {
        enemies = weakest; = leastHealth;
    return weakest;

while(true) {
    // Find the weakest enemy with the function:
    var weakestShaman = findWeakestEnemy();
    // If the weakest enemy exists:
    if (weakestShaman) {
        // Attack it!

Here is the problem. Try to go through each element of the enemies array and check if their health is less than leastHealth and if so, then update weakest to be that enemy and update leastHealth to be enemy’s health.