Skip to content

Commit abc5ab5

Browse files
author
Srinjoy Pati
committed
Vanilla stopwatch
1 parent 9862da5 commit abc5ab5

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed

Vanilla stopwatch/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# vanilla stopwatch using javascript
2+
## tech stack
3+
- HTML
4+
- CSS
5+
- JS
6+
## look

Vanilla stopwatch/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>stopwatch</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<div class="stop">
12+
<span id="Hour">00</span>:
13+
<span id="Min">00</span>:
14+
<span id="Sec">00</span>.
15+
<span id="Ms">00</span>
16+
</div>
17+
<div class="button">
18+
<button id="start">start</button>
19+
<button id="stop">stop</button>
20+
<button id="Reset">Reset</button>
21+
</div>
22+
<script src="script.js"></script>
23+
</body>
24+
</html>

Vanilla stopwatch/script.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
let Ms = 0;
2+
let Min = 0;
3+
let Hour = 0;
4+
let Sec = 0;
5+
6+
let MsString = document.getElementById('Ms');
7+
let SecString = document.getElementById('Sec');
8+
let HourString = document.getElementById('Hour');
9+
let MinString = document.getElementById('Min');
10+
11+
let startBtn = document.getElementById('start');
12+
let stopBtn = document.getElementById('stop');
13+
let ResetBtn = document.getElementById('Reset');
14+
15+
let interval;
16+
17+
function stopw(){
18+
Ms++;
19+
if(Ms == 100){
20+
Ms = 0;
21+
Sec++;
22+
MsString.innerHTML = Ms;
23+
}
24+
if(Sec == 60){
25+
Sec = 0;
26+
Min++;
27+
SecString.innerHTML = Sec;
28+
}
29+
if(Min == 60){
30+
Min = 0;
31+
Hour++;
32+
MinString.innerHTML = Min;
33+
}
34+
if(Ms < 10){
35+
MsString.innerHTML = '0' + Ms;
36+
}
37+
else{
38+
MsString.innerHTML = Ms;
39+
}
40+
if(Sec < 10){
41+
SecString.innerHTML = '0' + Sec;
42+
}
43+
else{
44+
SecString.innerHTML = Sec;
45+
}
46+
if(Min < 10){
47+
MinString.innerHTML = '0' + Min;
48+
}
49+
else{
50+
MinString.innerHTML = Min;
51+
}
52+
if(Hour < 10){
53+
HourString.innerHTML = '0' + Hour;
54+
}
55+
else{
56+
HourString.innerHTML = Hour;
57+
}
58+
}
59+
function startTimer(){
60+
clearInterval(interval);
61+
interval = setInterval(stopw, 10);
62+
}
63+
function stopTimer(){
64+
clearInterval(interval);
65+
66+
}
67+
68+
function resetTimer(){
69+
clearInterval(interval);
70+
Ms = 0;
71+
Sec = 0;
72+
Min = 0;
73+
Hour = 0;
74+
75+
MsString.innerHTML = '00';
76+
SecString.innerHTML = '00';
77+
MinString.innerHTML = '00';
78+
HourString.innerHTML = '00';
79+
}
80+
81+
startBtn.addEventListener('click', startTimer);
82+
stopBtn.addEventListener('click', stopTimer);
83+
ResetBtn.addEventListener('click', resetTimer);

Vanilla stopwatch/style.css

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
body{
7+
height: 100vh;
8+
background-color: #0a1e29;
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
flex-direction: column;
13+
font-family: sans-serif;
14+
}
15+
.stop{
16+
color: #fff;
17+
font-size: 5em;
18+
}
19+
.button button{
20+
background-color: #fff;
21+
border: none;
22+
border-radius: 10px;
23+
padding: 10px;
24+
font-size: 1.25em;
25+
font-weight: 600 ;
26+
margin: 0 10px;
27+
cursor: pointer;
28+
}
29+
#start{
30+
background-color: aquamarine;
31+
}
32+
#stop{
33+
background-color: yellow;
34+
}
35+
#Reset{
36+
background-color: red;
37+
}

0 commit comments

Comments
 (0)