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 (enemies.health < leastHealth) {
        enemies = weakest;
        enemy.health = leastHealth;
    }
    return weakest;
    
}

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

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.

Andrei