showing results for - "javascript countdown 1 minute"
Soren
30 Jun 2019
1<script>
2        function startTimer(duration, display) {
3            var timer = duration, minutes, seconds;
4            setInterval(function () {
5                minutes = parseInt(timer / 60, 10);
6                seconds = parseInt(timer % 60, 10);
7
8               // minutes = minutes < 10 ? "0" + minutes : minutes;
9                seconds = seconds < 10 ? "0" + seconds : seconds;
10
11                display.textContent =  seconds;
12
13                if (--timer < 0) {
14                    timer = duration;
15                }
16            }, 1000);
17        }
18
19        window.onload = function () {
20            var fiveMinutes = 60 * 5,
21                display = document.querySelector('#time');
22            startTimer(fiveMinutes, display);
23        };
24    </script>
25   
26<span id="time"></span>