Created
December 27, 2021 11:11
-
-
Save mailtodanish/bc3d44e5b96fb649c0c421fa3c899aee to your computer and use it in GitHub Desktop.
stop watch in js
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
var timer = document.getElementById("timer"); | |
var idealTimer = document.getElementById("ideal"); | |
var runningId; | |
var idealId; | |
var value = "0:0"; | |
var Idealvalue = "00:00"; | |
function startTimer(m, s) { | |
value = m + ":" + s; | |
if (s == 60) { | |
m = m + 1; | |
s = 0; | |
} | |
s = s + 1; | |
timer.textContent = value; | |
runningId = setTimeout(function () { | |
startTimer(m, s) | |
}, 1000); | |
} | |
function idealTimer1(m, s) { | |
console.log(m,s); | |
Idealvalue = m + ":" + s; | |
if (s == 60) { | |
m = m + 1; | |
s = 0; | |
} | |
s = s + 1; | |
idealTimer.textContent = Idealvalue; | |
idealId = setTimeout(function () { | |
idealTimer1(m, s) | |
}, 1000); | |
} | |
function pauseTimer() { | |
clearTimeout(runningId); | |
var k = Idealvalue.split(":"); | |
idealTimer1(parseInt(k[0], 10), parseInt(k[1], 10)); | |
} | |
function resumeTimer() { | |
clearTimeout(idealId); | |
var t = value.split(":"); | |
startTimer(parseInt(t[0], 10), parseInt(t[1], 10)); | |
} |
Author
mailtodanish
commented
Dec 27, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment