-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
101 lines (90 loc) · 2.11 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
let btn1 = document.getElementById("start_btn");
let btn2 = document.getElementById("stop_btn");
let btn3 = document.getElementById("reset_btn");
let timer_text = document.getElementById("timer_text");
btn1.addEventListener("click" , Start);
btn2.addEventListener("click" , Stop);
btn3.addEventListener("click" , Reset);
let check = false;
let check_for_start = false;
let milliSeconds = 0;
let seconds = 0;
let minutes = 0;
let hours = 0;
let event_value;
let ms, s , m , h;
function Start() {
if(check_for_start === true) return;
check = true;
check_for_start = true;
event_value = setInterval(function(){
milliSeconds += 5;
if(milliSeconds === 1000) {
milliSeconds = 0;
seconds++;
}
if(seconds === 60) {
seconds = 0;
minutes++;
}
if(minutes === 60) {
minutes = 0;
hours++;
}
if(hours === 24) {
Reset();
}
//milliseconds
if(milliSeconds < 10) {
ms = "00" + milliSeconds;
}
else if(milliSeconds < 100) {
ms = "0" + milliSeconds;
}
else {
ms = milliSeconds;
}
//seconds
if(seconds < 10) {
s = "0" + seconds;
}
else {
s = seconds;
}
//minutes
if(minutes < 10) {
m = "0" + minutes;
}
else {
m = minutes;
}
//hours
if(hours < 10) {
h = "0" + hours;
}
else {
h = hours;
}
timer_text.innerHTML = h + " : " + m + " : " + s + " : " + ms;
},5)
}
//Stop
function Stop() {
if(check === false) return;
clearInterval(event_value);
start_btn.innerText = "RESUME";
check_for_start = false;
}
//Reset
function Reset() {
check = false;
check_for_start = false;
milliSeconds = 0;
seconds = 0;
minutes = 0;
hours = 0;
timer_text.innerHTML = "00 : 00 : 00 : 000";
clearInterval(event_value);
start_btn.innerText = "START";
}
// code by M ANSHIF