Air Bridge (JavaScript)

I can’t complete this level for some reason I followed the instructions and also asked my friend, this is my code is it something wrong with the code?

// Help peasants to escape.

function onSpawn(e) {
    // We need to save three peasants.
    var remainingPeasants = 3;
    while (remainingPeasants > 0) {
        // Take a good position.
        pet.moveXY(40, 55);
        var peasant = pet.findNearestByType("peasant");
        if (peasant) {
            // Carry the peasant to the center passage.
            pet.carryUnit(peasant, 40, 34); 
            remainingPeasants -= 1;
        }
    }
    var munchkin = pet.findNearestByType("munchkin");
    // Carry a munchkin to the fire traps:
    if (munchkin) {
        pet.carryUnit(munchkin, 19, 40);
    }
}

pet.on("spawn", onSpawn);

// Fight!
while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
}

 
1 Like

For hints see Air Bridge In Sarven Desert using the Python Coding Language
There is also a link to a “video solution” in the last post

1 Like

Hello, I have fixed your code, check it and tell me how it works for you! :smiley:

[Solution removed by moderator]

Hi this person is not active anymore and please dont post solutions.

1 Like