-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasjs.js
154 lines (140 loc) · 4.13 KB
/
asjs.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const g=document.getElementById('sec');
const m=document.getElementById('min');
// start button
const s=document.getElementById('start');
// pause button
const p=document.getElementById('pause');
// reset buttton
const r=document.getElementById('reset');
const ms=document.getElementById('msec');
const rs=document.getElementById('res');
// dark mode
const b=document.getElementById('body');
const br=document.getElementById('dark');
const hd=document.getElementById('hr');
//INPUT min
let a=0,h=0;
//input sec
br.addEventListener("click",function()
{
// console.log('vhgvhg')
// switch from dark mode to normal mode
b.classList.toggle("light",);
if(br.innerHTML=="Dark mode")
{
br.innerHTML="Normal mode ";
}
else
{
br.innerHTML="Dark mode";
}
}
)
// start button listner
s.addEventListener("click",function()
{
rs.innerHTML="";
s.disabled = true;
p.disabled = false;
// sec
var i = 0;
// millisec
var j =0;
// setting an interval of 1000millisecond
var interval = setInterval(function()
{
// millisecond loop
var interval1=setInterval(function()
{
if(j<100)
{
if(j<10)
{
msec.innerHTML=`0${j}`
}
else{
msec.innerHTML=j;
}
j++;
if(j==100)
{
j=0;
}
}
},10)
// minute,hour and second loop
if(i<=60)
{
// console.log(i);
if(i<10)
{
// for two digit number
g.innerHTML=`0${i}`
}
else
{
// align second value to html element
g.innerHTML=i;
}
i++;
}
if(a<10)
{
// for two digit number
m.innerHTML=`0${a}`;
}
else{
// align minute value to html element
m.innerHTML=a;
}
if(i==60)
{
// increment hour after a 60 second
a++;
i=0;
}
if(a==60)
{
a=0;
// increment hour after a 60 minute
h++;
// align second value to html element
hd.innerHTML=h;
}
if(h==12)
{
h=0;
i=0;
a=0;
j=0;
}
// Reset button action listner
r.addEventListener("click",function()
{
// clear the current interval
clearInterval(interval);
clearInterval(interval1);
// set back default values
g.innerHTML="00";
m.innerHTML="00";
msec.innerHTML="00";
rs.innerHTML="";
// reenable disabled button
s.disabled = false;
p.disabled = true;
})
// Pause button event listner
p.addEventListener("click",function()
{
clearInterval(interval);
clearInterval(interval1);
// Display result
rs.innerHTML=`Time elapsed ${h} hours ${a} min ${i-1} seconds ${j-1} millisecond`;
// reenable disabled button
s.disabled = false;
// console.log(a);
// console.log(i);
// console.log(j);
})
}, 1000);
})