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
35 changes: 34 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
function setAlarm() {}
let timer;
function setAlarm() {
const input = document.getElementById("alarmSet");
let seconds = Number(input.value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens when seconds are 0 or negative?


const timeRemaining = document.getElementById("timeRemaining");

clearInterval(timer);

function updateDisplay() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job putting the code for formatting into an own function. This makes it reusable and easier to change the formatting if needed

const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;

const formattedTime =
String(minutes).padStart(2, "0") +
":" +
String(remainingSeconds).padStart(2, "0");

timeRemaining.textContent = `Time Remaining: ${formattedTime}`;
}

updateDisplay();

timer = setInterval(() => {
if (seconds > 0) {
seconds--;
updateDisplay();
} else {
clearInterval(timer);
playAlarm();
document.body.style.backgroundColor = "red";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The color stays red when the timer is restarted. How can you change this?

}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
7 changes: 4 additions & 3 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<!DOCTYPE html>
<!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>Title here</title>
<title>Alarm clock app</title>
</head>
<body>
<div class="centre">
<h2>⏰ Alarm Clock</h2>
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />
<input id="alarmSet" type="number" placeholder="Seconds" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down
34 changes: 34 additions & 0 deletions Sprint-3/alarmclock/style.css

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice stylings. This makes the page look nicer

Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,37 @@
h1 {
text-align: center;
}

body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}

.centre {
background-color: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 10px gray;
}

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

#set {
background-color: green;
color: white;
}

#stop {
background-color: red;
color: white;
}

button:hover {
opacity: 0.9;
}
Loading