Stuck at Vital Powers


Hello Guys,

Need your help in this, my hero never stops gathering coins and execute the next 2 functions:

// This level shows how to define your own functions.
// The code inside a function is not executed immediately. It's saved for later.
// This function has your hero collect the nearest coin.
this.pickUpNearestCoin = function() {
    var items = this.findItems();
    var nearestCoin = this.findNearest(items);
    if(nearestCoin) {

// This function has your hero summon a soldier.
this.summonSoldier = function() {
    // Fill in code here to summon a soldier if you have enough gold.
    if ( < this.costOf("soldier") ) {

// This function commands your soldiers to attack their nearest enemy.
this.commandSoldiers = function() {
    var friends = this.findFriends();
    for(var i=0; i < friends.length; i++) {
        var enemy = friends[i].findNearestEnemy();
        if(enemy) {
            this.command(friends[i],"attack", enemy);

loop {
    // In your loop, you can "call" the functions defined above.
    // The following line causes the code inside the "pickUpNearestCoin" function to be executed.
    // Call summonSoldier here
    // Call commandSoldiers here

please help


You check if your gold is less than the cost of a soldier. Since your gold is 20, and will never go down unless you summon something, you will never summon a soldier.


Thanks for help :slightly_smiling:
I am very new to coding and have not understood what to change.
Please help.


If the arrow < points left it is Less (both start with L)
Of course your gold will never be less than the cost of a soldier… And if it ever were, you wouldn’t be able to summon a soldier.

What you should check is whether you have enough money (gold > cost) to make a soldier