-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (27 loc) · 876 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var timer = 0;
var timerInterval;
var ms = document.getElementById('milliseconds');
var second = document.getElementById('mainsecond');
var minute = document.getElementById('mainminute');
function start(){
stop();
timerInterval = setInterval( function(){
timer += 1/60;
msVal = Math.floor((timer - Math.floor(timer) )*100);
secondVal = Math.floor(timer) - Math.floor(timer/60) *60;
minuteVal = Math.floor(timer/60);
ms.textContent = msVal <10 ? "0" + msVal.toString() : msVal;
second.textContent = secondVal < 10 ? "0" + secondVal.toString() : secondVal;
minute.textContent = minuteVal < 10 ? "0" + minuteVal.toString() : minuteVal;
}, 1000/60);
}
function stop(){
clearInterval(timerInterval);
}
function reset(){
stop();
timer = 0;
ms.textContent = '00';
second.textContent = '00';
minute.textContent = '00';
}