-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (79 loc) · 1.94 KB
/
index.html
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
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
.button5 {background-color: #555555;} /* Black */
</style>
<script src="index.js"></script>
<div class="button button5"><label>Stopwatch</label><div>
<br><div>Hr:Min:Sec</div>
<div id = 'timer'>00:00:00</div>
</div></div>
<br>
<button class="button" id="Start">Start</button>
<button class="button button2" id="Pause">Pause</button>
<button class="button button3" id="Reset">Reset</button>
<button class="button button4" id="CountDown">CountDown</button>
<body>
<script>
var timer;
var sec = 0;
var min = 0;
var hours = 0;
var element = document.getElementById('timer');
document.getElementById('Start').onclick = function () {
timer = setInterval(() => {
if (sec > 59) {
sec = 0;
min++;
} else if (min > 59) {
sec = 0;
hours++;
}
element.innerHTML = hours + ':' + min + ':' + sec;
sec++;
}, 1000);
};
document.getElementById('Pause').onclick = function () {
clearInterval(timer);
};
document.getElementById('Reset').onclick = function () {
sec = 00;
hours = 00;
min = 00;
element.innerHTML = '00:00:00';
clearInterval(timer);
};
document.getElementById('CountDown').onclick = function () {
clearInterval(timer);
timer = setInterval(() => {
if (sec > 0) {
sec--;
} else if (min > 0) {
min--;
sec = 59;
} else if(hours > 0){
hours--;
min = 59;
}
element.innerHTML = hours + ':' + min + ':' + sec;
if (sec === 0 && min === 0) {
clearInterval(timer);
}
}, 1000);
};
</script>
</body>