Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timer() {
- let time, intervalID;
- let startBtn = $("#start-timer");
- let stopBtn = $("#stop-timer");
- let isPaused = false;
- startBtn.click(function () {
- if (isPaused == false) {
- time = -1;
- }
- else {
- time -= 1;
- }
- incrementTime();
- intervalID = setInterval(incrementTime, 1000);
- startBtn.attr('disabled', true);
- stopBtn.attr('disabled', false);
- });
- stopBtn.on('click', function () {
- clearInterval(intervalID);
- isPaused = true;
- startBtn.attr('disabled', false);
- stopBtn.attr('disabled', true);
- });
- function incrementTime() {
- time++;
- $("#seconds").text(('0' + (time % 60)).slice(-2));
- $("#minutes").text(('0' + Math.trunc(time / 60) % 60).slice(-2));
- $("#hours").text(('0' + Math.floor(time / 3600) % 24).slice(-2))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment