I'm currently working on developing a boxing or countdown timer. So far, I have managed to get it functioning and updating the div content successfully. However, I encountered an issue where adding a prompt caused the function to be called endlessly. Although I can observe the div being updated, it prevents the rest of my code from executing as intended. Any advice on how to overcome this obstacle would be greatly appreciated.
function timerStart() {
let timerString = prompt("Enter Num");
/*let timerString = document.getElementById("div0").textContent;*/
let [minutes, seconds] = timerString.split(":").map(Number);
if (seconds > 0) {
seconds--;
console.log(seconds);
} else if (minutes > 0) {
minutes--;
seconds = 59;
console.log(minutes);
} else {
clearInterval(intervalTime);
return;
}
let newTimerString = `${minutes.toString().padStart(2, "0")}:${seconds
.toString()
.padStart(2, "0")}`;
document.getElementById("div0").textContent = newTimerString;
}
function startTimer() {
intervalTime = setInterval(timerStart, 1000);
}
document.getElementById("butt").addEventListener("click", startTimer);`
I attempted moving the prompt outside of the function, but that proved unsuccessful. Furthermore, trying to add a return statement at the end of the prompt function resulted in halting the entire process.