Help Sarven sum JS [solved]

Hello guys,
I m looking for help with the fire-trap calculation part… here is my code.


any suggestions ? :slight_smile:

Welcome to the discourse @osmo! :tada:
Can you please post your code in between three backticks? (these: ```)

1 Like
var whiteX = {x: 27,y: 42};
var redX = {x: 151,y: 118};

function calctraps() {
    var traps = hero.findByType("fire-trap");
    var index = 0;
    var min = 999;
    var max = 0;
    var trap = traps[index];
    while (index < traps.length) {
        if (trap.value < min) {
           min = trap.value;
        }
        if (trap.value > max) {
            max = trap.value;
        }
        index++;
    }
    var resultat = (min + max);
    return resultat;
}

hero.moveXY(27, 42);
hero.say(calctraps());

while (true) {
    while (hero.pos.x != 151 && hero.pos.y != 118) {
        var item = hero.findNearestItem();
        var enemy = hero.findNearestEnemy();
        if (!enemy) {
            var enemy = hero.findNearestEnemy();
            hero.move(redX);
        }
        if (enemy || item) {
            if (enemy) {
                if (hero.isReady("chain-lightning")) {
                    hero.cast("chain-lightning", enemy);
                }
                while (enemy.health > 0) {
                    hero.attack(enemy);
                }
            }
            if (item) {
                hero.moveXY(item.pos.x, item.pos.y);
            }
        }
    }
}

1 Like

Welcome to the forum :partying_face:
Try making two separate functions each for min and max, and please repost your code if it didn’t work

I found the solution,
var trap = traps[index];
declaration was not in the while

:face_with_hand_over_mouth:

1 Like

congrats please mark this topic as solved

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