summaryrefslogtreecommitdiff
path: root/to/js/countdown.js
blob: 5fc30396108728d547272873f574e852657e4c87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function startTimer(duration, display) {
    var timer = duration,
        minutes, seconds;
    setInterval(function () {
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);

        // minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "" + seconds : seconds; // In "" should be 0

        display.textContent = seconds;
        // Original with minutes
        // display.textContent = minutes + ":" + seconds;

        if (--timer < 0*60) {
            timer = duration;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 4 * 1, // 60 * 5
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};