-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
137 lines (112 loc) · 3.35 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const playBtn = document.getElementsByClassName("playbtn")[0];
const lapBtn = document.getElementsByClassName("lapbtn")[0];
const resetBtn = document.getElementsByClassName("resetbtn")[0];
const lapS = document.getElementsByClassName("laps")[0];
const clearBtn = document.getElementsByClassName("clearbtn")[0];
const innerCircle = document.getElementsByClassName("inner-circle")[0];
const sec = document.getElementsByClassName("sec")[0];
const msec = document.getElementsByClassName("msec")[0];
const min = document.getElementsByClassName("min")[0];
let secCounter = 0;
let secs;
let msecCounter = 0;
let msecs;
let minCounter = 0;
let mins;
let lapItem = 0;
const toggleBtn = () => {
lapBtn.classList.add("visibility");
resetBtn.classList.add("visibility");
};
const play = () => {
toggleBtn();
if (playBtn.innerHTML === "Start") {
playBtn.innerHTML = "Pause";
mins = setInterval(() => {
min.innerHTML = `${++minCounter} :`;
if (minCounter < 10) {
min.innerHTML = `0${minCounter} :`;
}
}, 60 * 1000);
secs = setInterval(() => {
if (secCounter === 59) {
secCounter = 1;
}
sec.innerHTML = `${++secCounter} :`;
if (secCounter < 10) {
sec.innerHTML = `0${secCounter} :`;
}
}, 1000);
msecs = setInterval(() => {
if (msecCounter === 99) {
msecCounter = 1;
}
msec.innerHTML = `${++msecCounter}`;
if (msecCounter < 10) {
msec.innerHTML = `0${msecCounter}`;
}
}, 10);
} else {
playBtn.innerHTML = "Start";
clearInterval(mins);
clearInterval(secs);
clearInterval(msecs);
}
if (playBtn.innerHTML === "Pause") {
lapBtn.classList.remove("visibility");
resetBtn.classList.remove("visibility");
}
};
const reset = () => {
clearInterval(mins);
clearInterval(secs);
clearInterval(msecs);
minCounter = 0;
secCounter = 0;
msecCounter = 0;
min.innerHTML = "00 :";
sec.innerHTML = " 00 :";
msec.innerHTML = " 00";
playBtn.innerHTML = "Start";
lapBtn.classList.add("visibility");
resetBtn.classList.add("visibility");
};
const lap = () => {
const li = document.createElement("li");
const number = document.createElement("span");
const timeStamp = document.createElement("span");
li.setAttribute("class", "lap-item");
number.setAttribute("class", "number");
timeStamp.setAttribute("class", "time-stamp");
number.innerHTML = `#${++lapItem}`
timeStamp.innerHTML = `${minCounter} :${secCounter} :${msecCounter}`;
li.append(number, timeStamp);
lapS.append(li);
clearBtn.classList.remove("laptime")
};
const clear = () => {
lapS.innerHTML = ""
lapS.append(clearBtn)
clearBtn.classList.add("laptime")
}
playBtn.addEventListener("click", play);
lapBtn.addEventListener("click", lap);
resetBtn.addEventListener("click", reset);
clearBtn.addEventListener("click", clear)
var watch = new stopwatchOn(timer);
function start(){
playBtn.textContent = 'Stop';
playBtn.classList.toggle('on');
watch.start();
}
function stop(){
playBtn.textContent = 'Start';
playBtn.classList.toggle("on")
watch.stop();
}
function stopwatchOn(){
playBtn.textContent = 'Start';
playBtn.classList.toggle("on")
watch.stop();
watch.reset();
}