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
61 changes: 60 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,56 @@
function setAlarm() {}
let countdownTimer;
let flashTimer;
let currentSeconds;

function setAlarm() {
clearInterval(countdownTimer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If Set Alarm is clicked while the previous alarm is still flashing, what happens to the existing flashTimer?

To "like" or "dislike" this comment, please follow this link

// fetch seconds input
currentSeconds = Number(document.getElementById("alarmSet").value);
document.body.style.backgroundImage = "url('alarmsethamster.jfif')";
document.body.style.backgroundPosition = "centre";
// set time remaining to seconds input
document.getElementById("timeRemaining").textContent =
`Time Remaining: ${formatTime(currentSeconds)}`;

// handling the interval and alarm end
countdownTimer = setInterval(() => {
currentSeconds = currentSeconds - 1;

document.getElementById("timeRemaining").textContent =
`Time Remaining: ${formatTime(currentSeconds)}`;

if (currentSeconds <= 0) {
clearInterval(countdownTimer);
playAlarm();
document.getElementById("timeRemaining").textContent =
`Time Remaining: 00:00`;

// img change
document.body.style.backgroundImage = "url('alarmplaysoundhamster.jfif')";
document.body.style.backgroundPosition = "center";

// box turns red
let flashCount = 0;
const box = document.querySelector(".centre");
flashTimer = setInterval(() => {
box.classList.toggle("red-bg");
flashCount++
if (flashCount >= 20){
clearInterval(flashTimer);
}
}, 500);
}
}, 1000);
}

function formatTime(totalSeconds) {
// converts the seconds to minutes and seconds and returns "mm:ss"
const convertToMinutes = Math.floor(totalSeconds / 60);
const remainderSeconds = totalSeconds % 60;
const paddedMinutes = String(convertToMinutes).padStart(2, "0");
const paddedSeconds = String(remainderSeconds).padStart(2, "0");
return `${paddedMinutes}:${paddedSeconds}`;
}

// DO NOT EDIT BELOW HERE

Expand All @@ -23,3 +75,10 @@ function pauseAlarm() {
}

window.onload = setup;

document.getElementById("stop").addEventListener("click", () => {
document.body.style.backgroundImage = "url('alarmsethamster.jfif')";
document.body.style.backgroundPosition = "center";
clearInterval(countdownTimer);
clearInterval(flashTimer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

After Stop clears flashTimer, what removes red-bg from .centre?

To "like" or "dislike" this comment, please follow this link

});
Binary file added Sprint-3/alarmclock/alarmplaysoundhamster.jfif
Binary file not shown.
Binary file not shown.
Binary file added Sprint-3/alarmclock/alarmsethamster.jfif
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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">
Expand Down
25 changes: 25 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
body {
background-image: url('alarmsethamster.jfif');
background-size: 700px 800px;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
margin: 0;
}

.centre {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
border-radius: 10px;
}

.red-bg {
background-color: rgba(201, 36, 36, 0.9) !important
}

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


#set {
font: serif;
}

#stop {
font: serif;
}
Loading