-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (50 loc) · 1.3 KB
/
Copy pathscript.js
File metadata and controls
74 lines (50 loc) · 1.3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let totalSeconds = 28800
let timerElement = document.getElementById("timer")
let startBtn = document.getElementById("start")
let pauseBtn = document.getElementById("pause")
let resetBtn = document.getElementById("reset")
let progressBar = document.getElementById("progressBar")
let timerInterval = null
function updateTimer(){
let hours = Math.floor(totalSeconds / 3600)
let minutes = Math.floor((totalSeconds % 3600) / 60)
let seconds = totalSeconds % 60
if(hours < 10){
hours = "0" + hours
}
if(minutes < 10){
minutes = "0" + minutes
}
if(seconds < 10){
seconds = "0" + seconds
}
let timeText = hours + ":" + minutes + ":" + seconds
timerElement.innerText = timeText
let progress = (28800 - totalSeconds) / 28800 * 100
progressBar.style.width = progress + "%"
}
function startTimer(){
if(timerInterval != null){
return
}
timerInterval = setInterval(function(){
if(totalSeconds > 0){
totalSeconds = totalSeconds - 1
updateTimer()
}
},1000)
}
function pauseTimer(){
clearInterval(timerInterval)
timerInterval = null
}
function resetTimer(){
clearInterval(timerInterval)
timerInterval = null
totalSeconds = 28800
updateTimer()
}
startBtn.onclick = startTimer
pauseBtn.onclick = pauseTimer
resetBtn.onclick = resetTimer
updateTimer()