-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (41 loc) · 1.04 KB
/
script.js
File metadata and controls
50 lines (41 loc) · 1.04 KB
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
let seconds = 0
let tens = 0
const displayTens = document.getElementById('tens')
const displaySeconds = document.getElementById('seconds')
const buttonStart = document.getElementById('button-start')
const buttonStop = document.getElementById('button-stop')
const buttonReset = document.getElementById('button-reset')
let interval
buttonStart.onclick = () => {
clearInterval(interval)
interval = setInterval(timer, 10)
}
buttonStop.onclick = () => {
clearInterval(interval)
}
buttonReset.onclick = () => {
clearInterval(interval)
tens = 0
seconds = 0
displayTens.innerHTML = `0${tens}`
displaySeconds.innerHTML = `0${seconds}`
}
const timer = () => {
tens++
if (Number(tens) <= 9) {
displayTens.innerHTML = `0${tens}`
}
if (Number(tens) > 9) {
displayTens.innerHTML = tens
}
if (Number(tens) > 99) {
console.log('seconds')
seconds++
displaySeconds.innerHTML = `0${seconds}`
tens = 0
displayTens.innerHTML = `0${tens}`
}
if (Number(seconds) > 9) {
displaySeconds.innerHTML = seconds
}
}