Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timer() {
- let tick = 0;
- let clockOn = false;
- let myInterval = null;
- function step() {
- tick++;
- let seconds = ('0' + tick % 60).slice(-2);
- $('#seconds').text(seconds);
- let minutes = ('0' + Math.floor(tick/ 60)).slice(-2);
- if(minutes>=60) {
- minutes-=60;
- minutes=('0'+minutes).slice(-2);
- }
- $('#minutes').text(minutes);
- let hours = ('0' + Math.floor(tick / 60/60)).slice(-2);
- $('#hours').text(hours);
- }
- function myStopFunction() {
- clearInterval(myInterval);
- clockOn=false;
- }
- $('#start-timer').on('click', function () {
- if (!clockOn) {
- myInterval = setInterval(step, 1000);
- }
- clockOn = true;
- });
- $('#stop-timer').on('click', myStopFunction);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement