Hey everyone, I'm new to coding and I could really use some help here. I have this code for a timer but I'm struggling to make it work properly even after refreshing the page. My goal is to keep the timer running smoothly, but I'm not sure what changes or additions need to be made in the code. Any guidance you can provide would be greatly appreciated!
<html>
<body>
<div id="countdown"></div>
<div id="notifier"></div>
<script type="text/javascript">
var t;
function cdpause(){
clearTimeout(t);
document.getElementById("notifier").innerHTML = " " ;
}
function startTimer() {
clearTimeout(t);
document.getElementById("notifier").innerHTML = " " ;
userInput = document.getElementById('userTime').value;
if(userInput.length == 0){
alert("Please enter a value");
} else {
var numericExpression = /^[0-9]+$/;
if(!userInput.match(numericExpression)){
alert("Please enter a number")
} else {
function display( notifier, str ) {
document.getElementById(notifier).innerHTML = str;
}
function toMinuteAndSecond( x ) {
return Math.floor(x/60) + ":" + x%60;
}
function setTimer( remain, actions ) {
(function countdown() {
display("countdown", toMinuteAndSecond(remain));
actions[remain] && actions[remain]();
(remain -= 1) >= 0
if(remain==-1){
}
else {
t = setTimeout(arguments.callee, 1000);
}
})();
}
setTimer(userInput, {
10: function () { display("notifier", "Just 10 seconds to go"); },
5: function () { display("notifier", "5 seconds left"); },
0: function () { display("notifier", "Time is up"); }
}
)};
}
}
</script>
Please Enter A Number: <input type="text" id="userTime" />
<input type="button" value="Go" onclick="startTimer()" />
<input type="button" onclick="cdpause()" value="Stop it" />
</body>
</html>