Created
April 24, 2020 01:29
-
-
Save Ifmr24/3546ac4d0d7fa12519a2d82977f9c363 to your computer and use it in GitHub Desktop.
timer with pause
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
class Timer { | |
constructor() { | |
this.time = 0; | |
this.interval = -1; | |
} | |
start() { | |
if (this.interval === -1) { | |
this.interval = setInterval(() => { | |
this.time++; | |
}, 1000); | |
} | |
} | |
pause() { | |
clearInterval(this.interval); | |
this.interval = -1; | |
} | |
seconds() { | |
return this.time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment