Skip to content
Open
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
63 changes: 62 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your implementation works really well good job

Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
function setAlarm() {}
let intervalId;
let seconds;
let timeRemaining = document.getElementById("timeRemaining");
let pause = false;
let setButton = document.getElementById("set");
let pauseAndResumeButton = document.getElementById("pauseAndResume");
let alarmInputField = document.getElementById("alarmInputField");

function calculateAndUpdate(seconds, timeRemaining) {
let mm = String(Math.floor(seconds / 60)).padStart(2, 0);
let ss = String(seconds % 60).padStart(2, 0);
timeRemaining.innerText = `Time Remaining: ${mm}:${ss}`;
}

function countDown() {
intervalId = setInterval(() => {
seconds -= 1;
calculateAndUpdate(seconds, timeRemaining);

if (seconds <= 0) {
clearInterval(intervalId);
playAlarm();
document.body.classList.add("flash-background");
pauseAndResumeButton.style.display = "none";
}
}, 1000);
}

function setAlarm() {
seconds = document.getElementById("alarmSet").value;
timeRemaining = document.getElementById("timeRemaining");

if (seconds > 0) {
calculateAndUpdate(seconds, timeRemaining);
setButton.style.display = "none";
pauseAndResumeButton.style.display = "block";
alarmInputField.style.display = "none";
countDown();
}
}

document.getElementById("stop").addEventListener("click", () => {
document.body.classList.remove("flash-background");
clearInterval(intervalId);
timeRemaining.innerText = `Time Remaining: 00:00`;
setButton.style.display = "block";
pauseAndResumeButton.style.display = "none";
alarmInputField.style.display = "block";
pauseAndResumeButton.innerText = "Pause";
pause = false;
});

document.getElementById("pauseAndResume").addEventListener("click", () => {
clearInterval(intervalId);
pause = !pause;
pause === true
? (pauseAndResumeButton.innerText = "Resume")
: (pauseAndResumeButton.innerText = "Pause");
if (pause === false) {
countDown();
}
});

// DO NOT EDIT BELOW HERE

Expand Down
17 changes: 12 additions & 5 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Alarm clock app</title>
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />
<div id="alarmInputField">
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" min="0" />
</div>

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
<div id="buttonField">
<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
<button id="pauseAndResume" type="button" style="display: none">
Pause
</button>
</div>
</div>
<script src="alarmclock.js"></script>
</body>
Expand Down
47 changes: 47 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}

#alarmSet {
Expand All @@ -13,3 +14,49 @@
h1 {
text-align: center;
}

@keyframes flash {
0% {
background-color: silver;
color: white;
}
50% {
background-color: white;
color: black;
}
100% {
background-color: silver;
color: white;
}
}

.flash-background {
animation: flash 1s infinite;
}

#alarmInputField {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
}

#alarmSet {
height: 30px;
max-width: 80px;
font-size: large;
text-align: center;
}

#buttonField {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
gap: 5px;
}

button {
border-radius: 8px;
font-size: medium;
margin-top: 8px;
}