Skip to content
Sign upLog in

How do i make a countdown timer?

Profile icon

I need help with making a countdown timer and notification system when it goes off, could anyone help? comment pls if you can!

You are viewing a single comment. View All
Profile icon

K, here's the code with the user input:

<div id="userInput"> <p>How many seconds do you want the timer to be? </p><input type="text" id="timerValue"><button onclick="setTimer()">Set Timer</button> </div> <button onclick="window.location = ''" style="display: none" id="restart">Restart</button> <p id="countdown">0</p> <script> function setTimer() { var userInput = document.getElementById("userInput"); = "none"; var restart = document.getElementById("restart"); = "block"; var timerValue = document.getElementById("timerValue"); var timer = timerValue.value; var timerText = document.getElementById("countdown"); clearTimeout() var countdown = setInterval(function() { if (timer == 0) { clearInterval(); /* End */ timerText.innerHTML = "Out of time!"; } else { timerText.innerHTML = timer; timer -= 1 /* Countdown */ }; }, 1000 /* Miloseconds */); } </script>

Yeesh, that's a lot of code! Sorry I took so long. Does it work?