-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.js
54 lines (51 loc) · 1.28 KB
/
page.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
52
53
54
let timerDisplay = document.getElementById("timerText");
let twentySeconds = document.getElementById("twentySecondsBtn");
let thirtSeconds = document.getElementById("thirtySecondsBtn");
let fortySeconds = document.getElementById("fortySecondsBtn");
let oneMinute = document.getElementById("oneMinuteBtn");
let timeCompletedText = "Your moment is completed !";
let secondsLeft = 0
let intervalId
clearTimer = () => {
clearInterval(intervalId)
}
clearTime = () => {
secondsLeft = 0
timerDisplay.textContent = ""
clearTimer()
}
setTimeAndShow = () => {
timerDisplay.textContent = secondsLeft
intervalId = setInterval(startTimer, 1000)
}
twentySeconds.onclick = () => {
//clearTime()
secondsLeft = 20
clearTimer()
setTimeAndShow()
}
thirtSeconds.onclick = () => {
//clearTime()
secondsLeft = 30
clearTimer()
setTimeAndShow()
}
fortySeconds.onclick = () => {
secondsLeft = 40
clearTimer()
setTimeAndShow()
}
oneMinute.onclick = () => {
secondsLeft = 60
clearTimer()
setTimeAndShow()
}
startTimer = () => {
if (secondsLeft > 1) {
secondsLeft = secondsLeft - 1
timerDisplay.textContent = secondsLeft + " second left"
} else {
clearInterval()
timerDisplay.textContent = timeCompletedText
}
}