Skip to content

Instantly share code, notes, and snippets.

@MohitDabas
Created December 31, 2019 15:07
Show Gist options
  • Save MohitDabas/f9a99c16fc54a09200beb065db0d0418 to your computer and use it in GitHub Desktop.
Save MohitDabas/f9a99c16fc54a09200beb065db0d0418 to your computer and use it in GitHub Desktop.
A simple javascript timer with start,stop,reset option
<!DOCTYPE html>
<head>
<script>
var timeCount=0
var dumb;
function startTimer()
{
digit=document.getElementById("digit");
timeCount=timeCount+1
digit.innerText=timeCount;
dumb=setTimeout(startTimer,1000)
}
function stopTimer(){
clearTimeout(dumb);
}
function resetTimer(){
digit=document.getElementById("digit");
digit.innerText=0;
timeCount=0;
clearTimeout(dumb);
}
</script>
</head>
<body>
<p id="digit">0</p>
<button id="start" onclick="startTimer()">Start</button>
<button id="stop" onclick="stopTimer()">Stop</button>
<button id="reset" onclick="resetTimer()">Reset</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment