[Solved] Alchemic Stack Javascript


#1

Hi,
I have a little problem, my peasant pick the potions, the mushrooms and the key, but he doesn’t give the items to yeti and to hero.
What is the problem with my code?
Thank you to help me

// Use mushrooms to weaken the Yeti.
// Use potions to heal the hero.
var yeti = hero.findNearestEnemy();
var peasant = hero.findFriends()[0];
var items = peasant.findItems();

for(var i = 0; i < items.length ; i++){
    var item = items[i];
    
    if(item.type != "gold-key"){
        // Use the "pickUpItem" command to take each item.
        hero.command(peasant, "pickUpItem", item);
    }
    
}
// Use the "dropItem" command to drop the top item.
// Drop the key near the door to open it.
var key = peasant.findNearestByType("gold-key");

hero.command(peasant, "pickUpItem", key);
hero.command(peasant, "dropItem", {"x": 39, "y": 34});

// Use peasant.peekItem() to access the item on top of the stack.
// Drop mushrooms at the yeti, potions at the hero.
var itemTop = peasant.peekItem();

    if(itemTop.type == "mushrooms"){
        hero.command(peasant, "dropItem", yeti.pos);
    }
    else if(itemTop.type == "potions"){
        hero.command(peasant, "dropItem",hero.pos);
    }


// Aaaand one (or two) final attacks to defeat the yeti.
hero.attack(yeti);

55


#2

That’s only going to drop 1 item. You need a loop for them to drop all of them.

Also, the item types are mushroom and potion, no s.

Also you need to update the ItemTop variable.