im stuck on computer science 5 level 6 “Mixed unit tactics”. my units attack and my hero moves but it wont spawn any more units. my hero spawns one then he just collects coins.
var summonTypes = ['archer','archer','soldier','soldier'];
var defendPoints = [{x: 40, y: 42},{x: 40, y: 26},{x: 40, y: 38},{x: 40, y: 33}];
function getCoins() {
while (true){
var coins = hero.findItems();
var coinIndex = 0;
var coin = coins[coinIndex];
if (coin) {
hero.move(coin.pos);
}
}
}
function summonTroops() {
var type = summonTypes[hero.built.length % summonTypes.length];
if(hero.gold >= hero.costOf(type)) {
hero.summon(type);
}
}
function commandTroops() {
var friends = hero.findFriends();
for(var friendIndex=0; friendIndex < friends.length; friendIndex++) {
var friend = friends[friendIndex];
var point = defendPoints[friendIndex % defendPoints.length];
if (friend.type == "archer"){
hero.command(friend, "defend", point);
}
}
}
while(true){
summonTroops();
commandTroops();
getCoins();
}