Computer Science, asked by Andika, 1 year ago

Any help ? 'How to create countdown using javaScript or jQuery'??

Answers

Answered by dhwani2013
1

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 ? "0" + seconds : seconds;

display.textContent = minutes + ":" + seconds;

if (--timer < 0) {

timer = duration;

}

}, 1000);

}

window.onload = function () {

var fiveMinutes = 60 * 5,

display = document.querySelector('#time');

startTimer(fiveMinutes, display);

};

<body>

<div>Registration closes in <span id="time">05:00</span> minutes!</div>

</body>


Andika: ty sir
dhwani2013: welcome
dhwani2013: stackoverflow is a helpful resource to solve such queries as well while coding
Andika: yes.. ty!
Similar questions