Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
47f91e5
Fix: update document title to 'Alarm clock app'
alexandru-pocovnicu Mar 16, 2026
41537a4
Fix: implement setAlarm function to display time remaining
alexandru-pocovnicu Mar 16, 2026
3ab9799
extract the seconds and minutes
alexandru-pocovnicu Mar 16, 2026
8a4ba11
Refactor: enhance setAlarm function to improve countdown display and …
alexandru-pocovnicu Mar 19, 2026
ca62e47
change background to blue when stop alarm is selected
alexandru-pocovnicu Mar 20, 2026
08fbcbd
alternate background color
alexandru-pocovnicu Mar 20, 2026
aa8df3b
deleted code for remove class
alexandru-pocovnicu Mar 20, 2026
950cd4a
added return when the input is 0, so timer doesn't start
alexandru-pocovnicu Apr 2, 2026
4aafd50
added function to clean the initial state
alexandru-pocovnicu Apr 3, 2026
dc665e5
add checks for valid input
alexandru-pocovnicu Apr 3, 2026
b81719d
create pause button,
alexandru-pocovnicu Apr 4, 2026
8354926
refactor CSS for consistency and clarity
alexandru-pocovnicu Apr 4, 2026
063a0fa
addresse reviewer's changes
alexandru-pocovnicu Apr 6, 2026
5d64c66
delete redundant code
alexandru-pocovnicu Apr 6, 2026
c84e2a9
created function to update display
alexandru-pocovnicu Apr 6, 2026
894313e
move countdown logic to finishCountDown()
alexandru-pocovnicu Apr 6, 2026
3b6db49
remove unused pause button styles and empty unpause-alarm class
alexandru-pocovnicu Apr 6, 2026
11d7474
capitalize unpause button text in pauseCountDown function
alexandru-pocovnicu Apr 6, 2026
5209ca9
remove class
alexandru-pocovnicu Apr 6, 2026
4251c18
remove id attribute from pause button in setAlarm function
alexandru-pocovnicu Apr 6, 2026
a65ca54
set pause button text and ensure event listener is added in setAlarm …
alexandru-pocovnicu Apr 6, 2026
6d09014
use display time logic instead of hard coding it
alexandru-pocovnicu Apr 9, 2026
6799a86
refactor cleanInitialState to use updateDisplayedTime for resetting d…
alexandru-pocovnicu Apr 9, 2026
fbb165f
initialize isPaused in cleanInitialState function
alexandru-pocovnicu Apr 9, 2026
74c4c23
remove event listener for pause button before adding a new one in set…
alexandru-pocovnicu Apr 9, 2026
35c4a7c
remove redundant assignment of remainingSeconds in setAlarm function
alexandru-pocovnicu Apr 12, 2026
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
31 changes: 30 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
function setAlarm() {}
function setAlarm() {
const alarmSetEl = document.getElementById("alarmSet");
const timeRemainingEl = document.getElementById("timeRemaining");
let totalSeconds = +alarmSetEl.value;
let intervalId;
function updateCountDown() {
let seconds = totalSeconds % 60;
let minutes = (totalSeconds - seconds) / 60;

let paddedSeconds = seconds.toString().padStart(2, "0");
let paddedMinutes = minutes.toString().padStart(2, "0");
timeRemainingEl.innerHTML = `Time Remaining: ${paddedMinutes}:${paddedSeconds}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better to implement the logic to "update the displayed time" in a function, and then use a function call to replace the code on lines 30-35, 66-71, 85.

Pros:

  • Centralised logic (improved maintainability)
  • Less code

alarmSetEl.value = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why clear the input field when updating the timer display? When a countdown is active, it will be cleared every second.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

didn't realise it was doing it every second , now there is a dedicated function to clear everything when the alarm is set


if (totalSeconds === 0) {
document.body.classList.add("finish-countdown")

playAlarm();
clearInterval(intervalId);

return;
}
totalSeconds -= 1;
}

updateCountDown();
intervalId = setInterval(updateCountDown, 1000);
}



// DO NOT EDIT BELOW HERE

Expand Down
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
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ First off, once you've branched off `main`, then update the title element in `in
You will need to write your implementation in `alarmclock.js`.

## How the clock should work

When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`.

Every one second the title should count down by one.
Expand Down
13 changes: 13 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
h1 {
text-align: center;
}

.finish-countdown {
animation: police 0.5s infinite;
}

@keyframes police {
from{
background-color:blue;
}
to{
background-color: red;
}
}
Loading