Untitled
unknown
javascript
3 years ago
1.3 kB
9
Indexable
const countdownElement = document.getElementById('countdown');
const pauseButton = document.getElementById('pause');
const resumeButton = document.getElementById('resume');
let countdownIntervalId;
let countdownTime;
function startCountdown() {
countdownIntervalId = setInterval(() => {
countdownTime--;
updateCountdown();
if (countdownTime === 0) {
clearInterval(countdownIntervalId);
countdownElement.innerHTML = 'Concluído!';
}
}, 1000);
}
function pauseCountdown() {
clearInterval(countdownIntervalId);
}
function resumeCountdown() {
startCountdown();
}
function updateCountdown() {
const hours = Math.floor(countdownTime / 3600);
const minutes = Math.floor((countdownTime - (hours * 3600)) / 60);
const seconds = countdownTime - (hours * 3600) - (minutes * 60);
countdownElement.innerHTML = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function setCountdownTime(time) {
countdownTime = time;
updateCountdown();
}
pauseButton.addEventListener('click', pauseCountdown);
resumeButton.addEventListener('click', resumeCountdown);
const initialCountdownTime = localStorage.getItem('countdownTime') || 60;
setCountdownTime(initialCountdownTime);
startCountdown();
Editor is loading...