Skip to content

Commit a2f4669

Browse files
authored
Merge pull request #32 from tajulafreen/Stop_Watch
50Projects-HTML-CSS-JavaScript : Stop watch
2 parents 89dde49 + 2b97e09 commit a2f4669

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ In order to run this project you need:
331331
</details>
332332
</li>
333333

334+
<li>
335+
<details>
336+
<summary>Stop Watch</summary>
337+
<p>This project is a simple and interactive stopwatch application created using HTML, CSS, and JavaScript. The stopwatch can be started, stopped, and reset, allowing users to measure elapsed time accurately. It displays minutes, seconds, and milliseconds, providing a clear and precise time tracking interface. The application is styled with CSS for a clean and modern look, and it is fully responsive, ensuring usability across different devices.</p>
338+
<ul>
339+
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/StopWatch/">Live Demo</a></li>
340+
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/StopWatch">Source</a></li>
341+
</ul>
342+
</details>
343+
</li>
344+
334345
</ol>
335346

336347
<p align="right">(<a href="#readme-top">back to top</a>)</p>

Source-Code/StopWatch/index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Stop watch</title>
7+
<link rel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Stopwatch</h1>
12+
<div class="stopwatch">
13+
<span id="minutes">00</span>:<span id="seconds">00</span>:<span
14+
id="milliseconds"
15+
>00</span
16+
>
17+
</div>
18+
<div class="buttons">
19+
<button id="start">Start</button>
20+
<button id="stop">Stop</button>
21+
<button id="reset">Reset</button>
22+
</div>
23+
</div>
24+
<script src="script.js"></script>
25+
</body>
26+
</html>

Source-Code/StopWatch/script.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let milliseconds = 0;
2+
let seconds = 0;
3+
let minutes = 0;
4+
let timer;
5+
6+
const startButton = document.getElementById('start');
7+
const stopButton = document.getElementById('stop');
8+
const resetButton = document.getElementById('reset');
9+
10+
const updateTime = () => {
11+
milliseconds += 1;
12+
if (milliseconds === 100) {
13+
milliseconds = 0;
14+
seconds += 1;
15+
}
16+
if (seconds === 60) {
17+
seconds = 0;
18+
minutes += 1;
19+
}
20+
document.getElementById('milliseconds').innerText = milliseconds < 10 ? `0${milliseconds}` : milliseconds;
21+
document.getElementById('seconds').innerText = seconds < 10 ? `0${seconds}` : seconds;
22+
document.getElementById('minutes').innerText = minutes < 10 ? `0${minutes}` : minutes;
23+
};
24+
25+
const startTimer = () => {
26+
clearInterval(timer);
27+
timer = setInterval(updateTime, 10);
28+
};
29+
30+
const stopTimer = () => {
31+
clearInterval(timer);
32+
};
33+
34+
const resetTimer = () => {
35+
clearInterval(timer);
36+
milliseconds = 0;
37+
seconds = 0;
38+
minutes = 0;
39+
document.getElementById('milliseconds').innerText = '00';
40+
document.getElementById('seconds').innerText = '00';
41+
document.getElementById('minutes').innerText = '00';
42+
};
43+
44+
startButton.addEventListener('click', startTimer);
45+
stopButton.addEventListener('click', stopTimer);
46+
resetButton.addEventListener('click', resetTimer);

Source-Code/StopWatch/style.css

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100vh;
6+
background-color: #2e2a2a;
7+
margin: 0;
8+
font-family: Arial, sans-serif;
9+
}
10+
11+
.container {
12+
display: flex;
13+
flex-direction: column;
14+
justify-items: center;
15+
align-items: center;
16+
}
17+
18+
.stopwatch,
19+
h1,
20+
span {
21+
color: aliceblue;
22+
}
23+
24+
.stopwatch {
25+
font-size: 48px;
26+
margin-bottom: 20px;
27+
}
28+
29+
.buttons {
30+
display: flex;
31+
justify-content: center;
32+
gap: 10px;
33+
}
34+
35+
button {
36+
padding: 10px 20px;
37+
font-size: 16px;
38+
cursor: pointer;
39+
border: none;
40+
border-radius: 5px;
41+
background-color: #007bff;
42+
color: #fff;
43+
}
44+
45+
button:active {
46+
background-color: #0056b3;
47+
}

0 commit comments

Comments
 (0)