Mixed Unit Tactics(C++)

// Practice using modulo to loop over an array

// Choose the mix and order of units you want to summon by populating this array:
var summonTypes = ["soldier","archer"];
this.toggleFlowers(false);
this.summonTroops = function() {
    // Use % to wrap around the summonTypes array based on this.built.length
    //var type = summonTypes[???];
    var type = summonTypes[this.built.length % summonTypes.length];
    if(this.gold >= this.costOf(type)) {
        this.summon(type);
    }
    //this.say("I should summon troops!");
};

this.pickUpNearestCoin = function() {
    var coin = this.findNearest(this.findItems());
    if (coin) {
        this.move(coin.pos);
    }
};

this.commandTroops = function() {
    var friends = this.findFriends();
    for(var i=0; i < friends.length; i++) {
        var friend = friends[i];
        var enemy = this.findNearest(this.findEnemies());
        if (friend && enemy && friend.type != 'palisade') this.command(friend, "attack", enemy);
    }
};

while (true) {
    this.summonTroops();
    this.pickUpNearestCoin();
    this.commandTroops();
}

Error Line 4