I get the following error message running my code below:
You need a string to check the cost of; one of [“soldier”, “archer”]
Strangely it highlights code I’ve used just fine in previous levels. The rest of my code is based on previous levels as well, so I’m stumped.
Can anyone help?
// 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", "soldier", "archer", "aoldier", "soldier", "soldier", "soldier", "archer", "archer", "archer", "soldier", "archer", "archer"];
this.summonTroops = function() {
// Use % to wrap around the summonTypes array based on this.built.length
var type = summonTypes[this.built.length % summonTypes.length];
// Error highlighted line below
if (this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.commandTroops = function(){
var troops = this.findFriends();
var troopSupply = troops.length;
var t, ally, enemy;
for(t = 0; t < troopSupply; t++){
ally = troops[t];
enemy = ally.findNearestEnemy();
if (ally.type != "palisade") {
this.command(ally, "attack", enemy);
}
}
};
this.pickUpNearestItem = function(){
var nearestItem = this.findNearest(this.findItems());
if (nearestItem) {
this.move(nearestItem.pos);
}
};
loop {
this.summonTroops();
this.commandTroops();
this.pickUpNearestItem();
}