This line is your problem (or at least a big part of the problem):
for (count > 0; count--;)
After the first time the timer handler runs, "count" will be -1. This loop will just keep going for a really long time.
You probably want
for (; count > 0; count--)
The for
loop header has three parts: initialization, test, and ... uhh, the third part, which is traditionally where you do iteration control but which really is just a place to put an expression. Your original code had the test expression first. That's not syntactically incorrect, because JavaScript just expects an expression, and a comparison expression like that is fine as far as that goes. It doesn't really do anything, however. The test expression in your version was count--
, which is also syntactically OK and not a bad thing for a test expression. However, because the interval handler never resets "count" to 0
, once it's decremented it to -1 the loop will keep going.