Steelclaw Gap Javascript

Hey guys,

Please help me with the code it think it something regarding modulus

this.summonTroops = function() {
    var type = summonTypes[this.built.length % summonTypes.length];
    if(this.gold >= this.costOf(type)) {
        this.summon(type);
    }
};


this.commandTroops = function() {
    var friends = this.findFriends();
    for(var friendIndex=0; friendIndex < friends.length; friendIndex++) {
        var friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
       defendPoints = defendPoints[ friendIndex % defendPoints.length ];
        // Command your minion to defend the defendPoint
        this.command(friend, "defend", defendPoints);
    }
};

loop {
    this.summonTroops();
    this.commandTroops();
}

Thanks in advance

1 Like

You are overwriting the defendPoints variable here (defendPoints = defendPoints[...]):

        defendPoints = defendPoints[ friendIndex % defendPoints.length ];
        // Command your minion to defend the defendPoint
        this.command(friend, "defend", defendPoints);

Try:

        var defendPoint = defendPoints[ friendIndex % defendPoints.length ];
        // Command your minion to defend the defendPoint
        this.command(friend, "defend", defendPoint);
1 Like

tried it but now showing a null error:

can you please tell, actually what is expected out of this level

thanks

1 Like

thanks got where i was wrong instead of defining a variable twice have changed the variable name :wink:

2 Likes