Mouse over the error sign (yellow triangle, red circle), a floating text box will appear describing the error.
The assignment for soldiers and soldierIndex is in a conditional block.
If the while (this.gold > this.costOf("soldier"))
condition is not true then soldiers will not be assigned a value
Also, the condition should be this.gold >=
(greater or equal)
I prefer to use a for loop to iterate through an array.
Always state the language you’re working in. (Some are very similar, but have minor differences. Looks like you’re in JScript)
You declare a variable named “len” and then never populate it.
You call that variable as though it were a function later passing it another variable len(soldiers).
All arrays have an element to measure their length. (arrName.length)