Try:
var count, time = 1000, intId; function invoke(){ intId = setInterval(function(){ count += 1; if(...)
You cannot change the interval dynamically because it is set once, and then setInterval code does not run again. So what can you do to clear the interval and set it to run again. You can also use setTimeout with similar logic, but with setTimeout you need to register a timeout every time, and you do not need to use clearTimeout if you do not want to interrupt between them. If you change the time every time, then setTimeout makes more sense.
var count, time = 1000; function invoke() { count += 1; time += 1000; //some new value console.log('displ'); window.setTimeout(invoke, time); } window.setTimeout(invoke, time);
source share