Skip to content

Commit

Permalink
week-10 done
Browse files Browse the repository at this point in the history
  • Loading branch information
hol23003 committed Apr 1, 2024
1 parent e987d9b commit 8618157
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions week-10/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stopwatch</title>
</head>

<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
.container {
margin-top: 100px;
}
#display {
font-size: 3em;
margin-bottom: 20px;
}
</style>

<body>

<div class="container">
<div id="display">00:00</div>
<button id="startStop">Start</button>
<button id="reset">Reset</button>
</div>

<script src="js/script.js"></script>

</body>
</html>
35 changes: 35 additions & 0 deletions week-10/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let seconds = 0;
let interval;
let running = false;

function updateTime() {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
document.getElementById('display').textContent = `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
}

function startStop() {
running = !running;
document.getElementById('startStop').textContent = running ? 'Stop' : 'Start';
if (running) {
interval = setInterval(incrementTime, 1000);
} else {
clearInterval(interval);
}
}

function incrementTime() {
seconds++;
updateTime();
}

function reset() {
clearInterval(interval);
seconds = 0;
updateTime();
running = false;
document.getElementById('startStop').textContent = 'Start';
}

document.getElementById('startStop').addEventListener('click', startStop);
document.getElementById('reset').addEventListener('click', reset);

0 comments on commit 8618157

Please sign in to comment.