Skip to content

Commit

Permalink
Merge pull request #268 from clownfish1805/clownfish1805-akksDev
Browse files Browse the repository at this point in the history
Timer application feature - issue #154
  • Loading branch information
iamrahulmahato authored Oct 4, 2024
2 parents 1761d5e + be882da commit 6737a77
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
39 changes: 39 additions & 0 deletions projects/timerapp/timer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Timer Application</title>
</head>
<body>
<div class="container">
<h1>Timer Application</h1>
<div class="timer" id="timer">00:00:00</div>
<div class="set-time">
<input type="number" id="setHours" placeholder="Hours" min="0" />
<input
type="number"
id="setMinutes"
placeholder="Minutes"
min="0"
max="59"
/>
<input
type="number"
id="setSeconds"
placeholder="Seconds"
min="0"
max="59"
/>
<button id="setTimerBtn">Set Timer</button>
</div>
<div class="buttons">
<button id="startBtn">Start</button>
<button id="stopBtn" disabled>Stop</button>
<button id="resetBtn">Reset</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
68 changes: 68 additions & 0 deletions projects/timerapp/timer/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
let timerInterval;
let totalSeconds = 0;

const timerDisplay = document.getElementById("timer");
const startBtn = document.getElementById("startBtn");
const stopBtn = document.getElementById("stopBtn");
const resetBtn = document.getElementById("resetBtn");
const setTimerBtn = document.getElementById("setTimerBtn");
const setHours = document.getElementById("setHours");
const setMinutes = document.getElementById("setMinutes");
const setSeconds = document.getElementById("setSeconds");

function updateTimerDisplay() {
const hours = String(Math.floor(totalSeconds / 3600)).padStart(2, "0");
const minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(
2,
"0"
);
const secs = String(totalSeconds % 60).padStart(2, "0");
timerDisplay.textContent = `${hours}:${minutes}:${secs}`;
}

function checkTime() {
if (totalSeconds <= 0) {
clearInterval(timerInterval);
alert("Time's up!");
startBtn.disabled = false;
stopBtn.disabled = true;
}
}

setTimerBtn.addEventListener("click", () => {
const hours = parseInt(setHours.value) || 0;
const minutes = parseInt(setMinutes.value) || 0;
const seconds = parseInt(setSeconds.value) || 0;

totalSeconds = hours * 3600 + minutes * 60 + seconds;
updateTimerDisplay();
startBtn.disabled = false;
stopBtn.disabled = true;
});

startBtn.addEventListener("click", () => {
if (totalSeconds > 0) {
startBtn.disabled = true;
stopBtn.disabled = false;

timerInterval = setInterval(() => {
totalSeconds--;
updateTimerDisplay();
checkTime();
}, 1000);
}
});

stopBtn.addEventListener("click", () => {
clearInterval(timerInterval);
startBtn.disabled = false;
stopBtn.disabled = true;
});

resetBtn.addEventListener("click", () => {
clearInterval(timerInterval);
totalSeconds = 0;
updateTimerDisplay();
startBtn.disabled = false;
stopBtn.disabled = true;
});
85 changes: 85 additions & 0 deletions projects/timerapp/timer/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
* {
box-sizing: border-box;
}

body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #ffebee;
font-family: Arial, sans-serif;
}

.container {
text-align: center;
background: rgba(255, 255, 255, 0.8);
/* Glassy feel */
backdrop-filter: blur(10px);
/* Glassy effect */
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
margin-bottom: 20px;
font-size: 24px;
color: #d81b60;
/* Dark pink color */
}

.timer {
font-size: 48px;
color: #2c3e50;
margin-bottom: 20px;
}

.set-time {
margin: 20px 0;
}

input {
width: 60px;
padding: 5px;
font-size: 16px;
margin: 0 5px;
border: 2px solid #d81b60;
/* Dark pink border */
border-radius: 5px;
}

input:focus {
outline: none;
border-color: #d81b60;
/* Dark pink border on focus */
}

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

button {
padding: 10px 20px;
font-size: 16px;
border: 2px solid #d81b60;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
background-color: white;
color: #d81b60;

}

button:hover {
background-color: #d81b60;/* Dark pink on hover */
color: white; /* White text on hover */
}

button:disabled {
background-color: rgba(216, 27, 96, 0.2);
color: #d81b60; /* Light pink feel for disabled button */
cursor: not-allowed;
}

0 comments on commit 6737a77

Please sign in to comment.