let timer = document.getElementById("timer")
let affirmation = document.getElementById("affirmation")
let timeout;
// Task:
// - Write a function to start the countdown timer on the button click and display it in the DOM.
Stop the timer when it reaches 0.
let timerInterval
function updateTimer() {
if (timeout[0] == '00' && timeout[1] === '00') {
stopTimer()
} else {
if (timeout[1] === '00') {
timeout[0] = (parseInt(timeout[0]) - 1).toString().padStart(2,'0')
timeout[1] = '59'
} else {
timeout[1] = (parseInt(timeout[1]) - 1).toString().padStart(2,'0')
}
timer.innerText = timeout.join(":")
}
}
function stopTimer() {
clearInterval(timerInterval);
}
btn.addEventListener('click',() => {
timeout = timer.innerText.split(":")
timerInterval = setInterval(updateTimer, 1000);
})
// Stretch goals:
// - Show a relaxing image in the background while the timer is running.
// - Play relaxing music.
const btn = document.getElementById("btn")