I’m trying to create a countdown for a pomodoro app but I don’t know how to stop it when it reaches 0. I’ve tried: clearInterval, minutes.innerHTML = “0”, and adding return with the condition if(minutes <= 0 && seconds <= 0)
<div class="card work">
<h2>Work</h2>
<p id="stopwatch">1:00</p>
<button id="start">Start</button>
</div>
const start = document.querySelector("#start");
start.addEventListener("click", updateCountdown);
const startingMinutes = 1;
let time = startingMinutes * 60;
const countdownEl = document.querySelector("#stopwatch");
setInterval(updateCountdown, 1000);
function updateCountdown() {
const minutes = Math.floor(time / 60);
let seconds = time % 60;
seconds = seconds < 10 ? "0" + seconds : seconds;
countdownEl.innerHTML = `${minutes}:${seconds}`;
time--;
if (minutes <= 0 && seconds <= 0) {
minutes.innerHTML = "00";
seconds.innerHTML = "00";
}
}