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
30 changes: 30 additions & 0 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
function setAlarm() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why keep this?


// DO NOT EDIT BELOW HERE
let countdown;

function setAlarm() {
let seconds = Number(document.getElementById("alarmSet").value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Without proper validation or pre-processing, some unusual input values can make your app behave abnormally. Can you add code to sanitise the input?


function updateDisplay() {
let mins = Math.floor(seconds / 60);
let secs = seconds % 60;
let mm = String(mins).padStart(2, "0");
let ss = String(secs).padStart(2, "0");
document.getElementById("timeRemaining").innerText =
"Time Remaining: " + mm + ":" + ss;
}

updateDisplay();
clearInterval(countdown);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you think of anything else that should also be reset?


countdown = setInterval(function () {
seconds--;
updateDisplay();

if (seconds <= 0) {
clearInterval(countdown);
playAlarm();
}
}, 1000);
}

var audio = new Audio("alarmsound.mp3");

Expand All @@ -19,7 +46,10 @@ function playAlarm() {
}

function pauseAlarm() {
/* Stop the bell and freeze the timer */
clearInterval(countdown);
audio.pause();
audio.currentTime = 0;
}

window.onload = setup;
43 changes: 43 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
margin: 0;
padding: 0;
}

.centre {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background: white;
padding: 30px 40px;
border-radius: 12px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
text-align: center;
}

h1 {
margin-bottom: 20px;
font-size: 24px;
color: #333;
}

#alarmSet {
Expand All @@ -12,4 +30,29 @@

h1 {
text-align: center;
border: 2px solid #ddd;
border-radius: 6px;
}

button {
padding: 10px 18px;
margin: 5px;
font-size: 15px;
border: none;
border-radius: 6px;
cursor: pointer;
}

#set {
background: #4caf50;
color: white;
}

#stop {
background: #e53935;
color: white;
}

button:hover {
opacity: 0.85;
}