Soy muy nuevo en la codificación, así que disculpe mi ignorancia. Estoy tratando de obtener una cuenta regresiva que muestre el mensaje "¡Y LOS VOTOS ESTÁN EN!" cuando el temporizador llega a cero. Luego quiero que se muestre el enlace https://www.youtube.com/watch?v=26WpGvLpFzw 5 segundos después de que finalice la cuenta regresiva (el mensaje "¡Y LOS VOTOS ESTÁN EN!" se mostrará durante 5 segundos, luego el se mostrará el enlace). Actualmente tengo el código para la cuenta regresiva, pero no para que los mensajes se muestren después de que finalice la cuenta regresiva. Mi código hasta ahora es:
<p> Voting period: <span id="countdowntimer">10 </span> Seconds</p> <script type="text/javascript"> var timeleft = 10; var downloadTimer = setInterval(function(){ timeleft--; document.getElementById("countdowntimer").textContent = timeleft; if(timeleft <= 0) clearInterval(downloadTimer); },1000); </script>Puede usar setTimeout , es algo similar a setInterval pero retrasa y ejecuta el código interno después de una cantidad determinada de milisegundos.
<p id="foo"> Voting period: <span id="countdowntimer">10 </span> Seconds</p> <script type="text/javascript"> var timeleft = 10; //added this next 4 lines for the link var a = document.createElement('a'); var link = document.createTextNode("https://www.youtube.com/watch?v=26WpGvLpFzw"); a.appendChild(link); a.href = "https://www.youtube.com/watch?v=26WpGvLpFzw"; var downloadTimer = setInterval(function() { timeleft--; document.getElementById("countdowntimer").textContent = timeleft; if (timeleft <= 0) { clearInterval(downloadTimer); document.getElementById("foo").innerHTML = "AND THE VOTES ARE IN!"; //added this part for the delay setTimeout(function() { document.getElementById("foo").innerHTML = ""; document.getElementById("foo").appendChild(a); }, 5000); } }, 1000); </script>