So I developed a countdown function, in the code below I test it with a 1 minute input, but the console throws all the values at once. What should happen is a number every second, I believe the problem is that setTimeout is probably not working, but how to fix?
function countdown(tempominutos) {
let tempo = new Date();
tempo.setHours(0, tempominutos, 0);
let tempoformatado = tempo.toLocaleTimeString();
console.log(tempoformatado);
while ((tempo.getSeconds() > 0) || (tempo.getMinutes() > 0) || (tempo.getHours() > 0)) {
tempo.setSeconds(tempo.getSeconds() - 1);
tempoformatado = tempo.toLocaleTimeString();
setTimeout(console.log(tempoformatado), 1000);
}
}
countdown(1);