Changing interval time to random?

Im looking for a way to change the way my javascript number counter is working. Now it just counts up every second but I want it to count at random times between 1 second and 15 seconds.

    function startCount()
{   timer = setInterval (count, 1000);  

}


function count()
{
    var el = document.getElementById('counter');
    var currentNumber = parseFloat(removeCommas(el.innerHTML));
    el.innerHTML = addCommas(currentNumber+1);
}



function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(d+)(d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2 + '.00';
}



function removeCommas(aNum) 
{
    //remove any commas
    aNum=aNum.replace(/,/g,"");

    //remove any spaces
    aNum=aNum.replace(/s/g,"");

return aNum;
}

Can someone help me change the count time to random numbers?


Source: javascript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.