Estoy tratando de hacer un temporizador de cuenta regresiva que se muestre solo desde las 8 am hasta las 16 y luego muestre un mensaje durante 16 horas y repita el mismo ciclo todos los días. Tengo este código, pero realmente no entiendo qué tiene de malo. ¿Alguna recomendación?
Valorar. ¡Gracias!
let getTom = () => { var tom = new Date(); tom.setDate(now.getDate() + (1 - now.getDay() % 1)); tom.setHours(16, 30, 0, 0); return tom; } window.onload = function() { var countDownDate = getTom(); let startCountdown = function() { // Countdown Timer var x = setInterval(function() { var now = new Date().getTime(); var distance = countDownDate - now; var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor( (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); var time = days + " days, " + hours + "h, " + minutes + "m, " + seconds + "s "; document.getElementById("time").innerText = time; if (distance < 0) { clearInterval(x); document.getElementById("time").innerText = "test"; setTimeout(() => { startCountdown(); // set to 16h later countDownDate = countDownDate.getTime() + (1000 * 60 * 60 * 16); }, (1000 * 60)) // 1m test } }); startCountdown();}}