1 minutes 30 second countdown timer javascript

I have the code but it’s for 2 minutes timer and i need it to modify to 1 minutes 30 seconds timer.

I have tried but fails to start timer from 1:30.

As i’m beginner in this line and want to learn how to do that.

here it’s the code

<div id=timer></div>
<script type="text/javascript">
  var timeoutHandle;

  function countdown(minutes, seconds) {
    var seconds = 60;
    var mins = minutes

    function tick() {
      var counter = document.getElementById("timer");
      var current_minutes = mins - 1
      seconds--;
      counter.innerHTML =
        current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
      if (seconds > 0) {
        timeoutHandle = setTimeout(tick, 1000);
      } else {

        if (mins > 1) {

          // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst
          setTimeout(function() {
            countdown(mins - 1);
          }, 1000);

        }
      }
    }
    tick();
  }

  countdown(2);
</script>

51 thoughts on “1 minutes 30 second countdown timer javascript”

  1. I will use something like this:

    <div id=timer></div>
    <script type="text/javascript">
    
        var maxTicks = 90;
        var tickCount = 0;
        
        var tick = function()
        {
            if (tickCount >= maxTicks)
            {
                // Stops the interval.
                clearInterval(myInterval);
                return;
            }
        
            /* The particular code you want to excute on each tick */
            document.getElementById("timer").innerHTML = (maxTicks - tickCount);
        
            tickCount++;
        };
        
        // Start calling tick function every 1 second.
        var myInterval = setInterval(tick, 1000);
    
    </script>
    
    Reply
  2. <div id=timer></div>
    <script type="text/javascript">
        var timeoutHandle;
        function countdown(minutes, seconds) {
            function tick() {
                var counter = document.getElementById("timer");
                counter.innerHTML =
                    minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
                seconds--;
                if (seconds >= 0) {
                    timeoutHandle = setTimeout(tick, 1000);
                } else {
                    if (minutes >= 1) {
                        // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst
                        setTimeout(function () {
                            countdown(minutes - 1, 59);
                        }, 1000);
                    }
                }
            }
            tick();
        }
    
        countdown(1, 30);
    </script>
    Reply

Leave a Comment