Resource Valleys: Help PLS!

I have no idea what to do on line 30. Please.

// Collect all the coins!
function commandPeasant(peasant, coins) {
    // Find the nearest coin to the `peasant` from the `coins` array,
    let peasants = hero.findFriends();
    for (let peasant of peasants) {
        let coin = peasant.findNearestItem();
        if (coin) {
            // Command the peasant "move" to the nearest coin.
    hero.command(peasant, "move", coin.pos);
        }
    }
}
let friends = hero.findFriends();
let peasants = {
    "Aurum":friends[0],
    "Argentum":friends[1],
    "Cuprum":friends[2]
};
while(true) {
    let items = hero.findItems();
    let goldCoins = [];
    let silverCoins = [];
    let letnzeCoins = [];
    for(let i = 0; i < items.length; i++) {
        let item = items[i];
        if(item.value == 3) {
            goldCoins.push(item);
        }
        // Put letnze and silver coins in their approriate array:
        
    }
    commandPeasant(peasants.Aurum, goldCoins);
    commandPeasant(peasants.Argentum, silverCoins);
    commandPeasant(peasants.Cuprum, letnzeCoins);
}

It is also giving me an error that says this:
Line 6: TypeError: Can’t read protected property: findNearestItem

On line thirty it is asking you to copy the code for the gold coins and use it to put the silver coins and letnze coins in their own arrays (silverCoins and letnzeCoins).
For your second error, codecombat sometimes doesn’t like when friendly units use functions, (Idk what causes it) try replacing it with
let coin = peasant.findNearest(hero.findItems());

Now there is something wrong with line 9. It’s giving me another error it says:
Line 9: ArgumentError: Hero Placeholder can’t command type "equestrian" (only types: soldier, archer, griffin-rider, peasant).

here’s my code again

// Collect all the coins!
function commandPeasant(peasant, coins) {
    // Find the nearest coin to the `peasant` from the `coins` array,
    let peasants = hero.findFriends();
    for (let peasant of peasants) {
        let coin = peasant.findNearest(hero.findItems());
        if (coin) {
            // Command the peasant "move" to the nearest coin.
    hero.command(peasant, "move", coin.pos);
        }
    }
}
let friends = hero.findFriends();
let peasants = {
    "Aurum":friends[0],
    "Argentum":friends[1],
    "Cuprum":friends[2]
}
while(true) {
    let items = hero.findItems();
    let goldCoins = [];
    let silverCoins = [];
    let letnzeCoins = [];
    for(let i = 0; i < items.length; i++) {
        let item = items[i];
        if(item.value == 3) {
            goldCoins.push(item);
        }
        // Put letnze and silver coins in their approriate array:
        letnzeCoins.push(item);
        silverCoins.push(item);
    }
    commandPeasant(peasants.Aurum, goldCoins);
    commandPeasant(peasants.Argentum, silverCoins);
    commandPeasant(peasants.Cuprum, letnzeCoins);
}
letnzeCoins.push(item);
silverCoins.push(item);

You need to check if the item value is correct before adding them to their arrays; like the gold coins. (letnzeCoins are value 1 and silverCoins are value 2)

Alright, I changed that, but it is still giving me an error that says the same thing.

// Collect all the coins!
function commandPeasant(peasant, coins) {
    let peasants = hero.findFriends();
    for (let peasant of peasants) {
        let coin = peasant.findNearest(hero.findItems());
        if (coin) {
            hero.command(peasant, "move", coin.pos);
        }
    }
}
let friends = hero.findFriends();
let peasants = {
    "Aurum": friends[0],
    "Argentum": friends[1],
    "Cuprum": friends[2]
};
while (true) {
    let items = hero.findItems();
    let goldCoins = [];
    let silverCoins = [];
    let letnzeCoins = [];
    for (let i = 0; i < items.length; i++) {
        let item = items[i];
        if (item.value == 3) {
            goldCoins.push(item);
        }
        // Put letnze and silver coins in their approriate array:
        if (item.value == 1) {
            letnzeCoins.push(item);
        }
        if (item.value == 2) {
            silverCoins.push(item);
        }
    }
    commandPeasant(peasants.Aurum, goldCoins);
    commandPeasant(peasants.Argentum, silverCoins);
    commandPeasant(peasants.Cuprum, letnzeCoins);
}

There is something wrong with line 7.

Do I need a semicolon on line 16? Can I just delete it?

Never mind, I figured it out!

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