 <p>You should also measure the length of the stick in the first part of the for loop, otherwise you'll be measuring it with every iteration. And you can also make the <code>k</code> bit even more compact:</p> <pre><code>for (var i = k = 0, j = mystick.length; i &lt; j; i++) { if (mystick[i] == 'huge') { k++; } } </code></pre>