Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timer() {
- let sec = 0;
- let timer;
- let startBtn = $('#start-timer');
- let stopBtn = $('#stop-timer');
- stopBtn.attr("disabled", true);
- startBtn.on("click", function (event) {
- startBtn.attr("disabled", true);
- stopBtn.attr("disabled", false);
- timer = setInterval(step, 1000);
- //alert("START");
- });
- stopBtn.on("click", function (event) {
- stopBtn.attr("disabled", true);
- startBtn.attr("disabled", false);
- clearInterval(timer);
- //alert("STOP");
- });
- function step() {
- sec++;
- let digSec = sec % 60;
- let digMin = parseInt((sec/60)%60);
- let digHour = parseInt(sec/3600);
- if (digSec < 10 ){
- digSec = '0' + digSec.toString();
- }
- if (digMin < 10 ){
- digMin = '0' + digMin.toString();
- }
- if (digHour < 10 ){
- digHour = '0' + digHour.toString();
- }
- $('#seconds').text(digSec);
- $('#minutes').text(digMin);
- $('#hours').text(digHour);
- }
- }
Add Comment
Please, Sign In to add comment