-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
57 lines (48 loc) · 1.46 KB
/
main.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
var countMinute =0;
var countSecond = 0;
var startBtn = document.getElementById("start");
var stopBtn = document.getElementById("stop");
var resetBtn = document.getElementById("reset");
// Calling Event listners
startBtn.addEventListener("click",onStart);
stopBtn.addEventListener("click",onStop);
resetBtn.addEventListener("click",onReset);
// Defining Events
function onStart(){
stopwatch = true;
setTimer();
}
function onStop(){
stopwatch = false;
startBtn.innerHTML = "Continue";
}
function onReset(){
stopwatch = false;
countMinute = 0;
countSecond = 0;
stopBtn.classList.add('fade');
startBtn.innerHTML = "Start";
document.getElementById("min").innerHTML = '00';
document.getElementById("sec").innerHTML = '00';
}
function setTimer(){
if(stopwatch){
countSecond += 1;
if(countSecond == 60){
countMinute+=1;
countSecond = 0;
}
let seconds = countSecond < 10 ? `0`+ countSecond : countSecond;
let minute = countMinute < 10 ? `0` + countMinute : countMinute;
document.getElementById('min').innerHTML = minute;
document.getElementById('sec').innerHTML = seconds;
setTimeout(setTimer, 1000);
}
}
function fadeOut(btn) {
var otherBtns = document.querySelectorAll('.button-container button:not(fade)');
for (var i = 0; i < otherBtns.length; i++) {
otherBtns[i].classList.remove('fade');
}
btn.classList.add('fade');
}