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

[SOLVED] Weakset Quikest lvl

hello, guys i dont inderstand why im stuck in this lvl can i have help plz… :confused:

function findWeakestEnemy() {
    var enemies = hero.findEnemies();
    var weakest = null;
    var leastHealth = 99999;
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        if (enemy.health < leastHealth) {
             var weakset = enemy;
             leastHealth = enemy.health;         
        }  
    enemyIndex +=1; 
    } 
    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);
    }
}

if i remove it, he dosen’t work :confused:

Line 10 needs to be the other way round:

weakest = enemy

like this i dont have any error, but my hero dont move …

function findWeakestEnemy() {
    var enemies = hero.findEnemies();
    var weakest = null;
    var leastHealth = 99999;
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        if (enemy.health < leastHealth) {
             leastHealth = enemy.health; 
             enemy = weakest; 
        }  
    enemyIndex +=1; 
    } 
    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);
    }
}

1 Like

thank u bro i dont see your message :slight_smile:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.