Skip to content

50Projects-HTML-CSS-JavaScript : Stop watch #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ In order to run this project you need:
</details>
</li>

<li>
<details>
<summary>Stop Watch</summary>
<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>
<ul>
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/StopWatch/">Live Demo</a></li>
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/StopWatch">Source</a></li>
</ul>
</details>
</li>

</ol>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
26 changes: 26 additions & 0 deletions Source-Code/StopWatch/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stop watch</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<h1>Stopwatch</h1>
<div class="stopwatch">
<span id="minutes">00</span>:<span id="seconds">00</span>:<span
id="milliseconds"
>00</span
>
</div>
<div class="buttons">
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="reset">Reset</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
46 changes: 46 additions & 0 deletions Source-Code/StopWatch/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let milliseconds = 0;
let seconds = 0;
let minutes = 0;
let timer;

const startButton = document.getElementById('start');
const stopButton = document.getElementById('stop');
const resetButton = document.getElementById('reset');

const updateTime = () => {
milliseconds += 1;
if (milliseconds === 100) {
milliseconds = 0;
seconds += 1;
}
if (seconds === 60) {
seconds = 0;
minutes += 1;
}
document.getElementById('milliseconds').innerText = milliseconds < 10 ? `0${milliseconds}` : milliseconds;
document.getElementById('seconds').innerText = seconds < 10 ? `0${seconds}` : seconds;
document.getElementById('minutes').innerText = minutes < 10 ? `0${minutes}` : minutes;
};

const startTimer = () => {
clearInterval(timer);
timer = setInterval(updateTime, 10);
};

const stopTimer = () => {
clearInterval(timer);
};

const resetTimer = () => {
clearInterval(timer);
milliseconds = 0;
seconds = 0;
minutes = 0;
document.getElementById('milliseconds').innerText = '00';
document.getElementById('seconds').innerText = '00';
document.getElementById('minutes').innerText = '00';
};

startButton.addEventListener('click', startTimer);
stopButton.addEventListener('click', stopTimer);
resetButton.addEventListener('click', resetTimer);
47 changes: 47 additions & 0 deletions Source-Code/StopWatch/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #2e2a2a;
margin: 0;
font-family: Arial, sans-serif;
}

.container {
display: flex;
flex-direction: column;
justify-items: center;
align-items: center;
}

.stopwatch,
h1,
span {
color: aliceblue;
}

.stopwatch {
font-size: 48px;
margin-bottom: 20px;
}

.buttons {
display: flex;
justify-content: center;
gap: 10px;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
}

button:active {
background-color: #0056b3;
}
Loading