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