This js will take a value, subtract X amount from it, and then count up to that value.
I attempted to accomplish this task by doing a simple while loop, but I couldn't get it work.
I was wondering if anyone could comment on how or why the while loop method below doesn't work.
This is the only way I could get it to work:
function _initCountUpUsers()
{
var totalUsers = $('#totalUsers');
var ceiling = parseInt(totalUsers.html());
var floor = ceiling - 10;
function updateTotalUsers()
{
if(floor < ceiling)
{
totalUsers.html(floor);
floor++;
}
}
window.setInterval(updateTotalUsers, 1000, floor);
}
Non-working While method:
function _initCountUpUsers()
{
var totalUsers = $('#totalUsers');
var ceiling = parseInt(totalUsers.html());
var floor = ceiling - 10;
function updateTotalUsers()
{
totalUsers.html(floor);
floor++;
}
while(floor < ceiling)
{
window.setInterval(updateTotalUsers, 1000, floor);
}
}