Created
December 31, 2019 15:07
-
-
Save MohitDabas/f9a99c16fc54a09200beb065db0d0418 to your computer and use it in GitHub Desktop.
A simple javascript timer with start,stop,reset option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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