Is there a way to create a timer that counts down from a specific range to zero instead of displaying 0:00 immediately without any changes using innerHTML? I tried using the sleep function, but it just keeps the screen the same until it displays zero. How can I make it look like an actual countdown? Please help!
function sleep(t){
let timeStart = new Date().getTime();
while(true)
{
let elapsedTime = new Date().getTime() - timeStart;
if(elapsedTime > t){
break;
}
}
}
function startLoop(){
let minutesValue = document.getElementById("minutes-input").value;
let secondsValue = document.getElementById("seconds-input").value;
let minutesDisplay = document.getElementById("minutes");
let secondsDisplay = document.getElementById("seconds");
for(var i=0;i < minutesValue; i++)
{
minutesDisplay.innerHTML=i;
console.log(i);
for (var j =1; j<=59; j++) {
sleep(1000);
secondsDisplay.innerHTML=j;
console.log(j);
}
}