-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
51 lines (39 loc) · 924 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var timer
var hour = 0
var minute = 0
var seconds = 0
var click = false
function start(){
if (!click){
timer = window.setInterval( function watch() {
seconds++
if (seconds == 60){
seconds = 0
minute++
}
if (minute == 60){
minute = 0
hour++
}
var stopWatch = number(hour) + ":" + number(minute) + ":" + number(seconds)
document.getElementById("h1").innerText = stopWatch
}, 1000)
click = true
}
}
function number(element) {
return element < 10 ? '0' + element : element;
}
function stop(){
clearInterval(timer)
click = false
}
function reset(){
clearInterval(timer)
click = false
hour = 0
minute = 0
seconds = 0
let h = document.getElementById("h1")
h.innerText = "00:00:00"
}