Search code examples
javascripttimecountdownintervals

Change time interval


How can I change or countdown my time interval? I want to popup "alert" every 5000ms, 4000ms, 3000ms, and so on.

intervall = 5000;

setInterval(function(){

  alert("ALERT");

  interval = interval - 1000;      
},intervall);

Solution

  • Try using setTimeout instead of setInterval.

    Like this:

    interval = 5000;
    
    setTimeout(function(){
    
      alert("ALERT");
    
      interval = interval - 1000;      
    },interval);