Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3a34f9f
updated title name placeholder to Alarm clock app
CatchingKiyoko Jul 14, 2025
0289a03
implemented: selects the users input field from the DOM to retrieve s…
CatchingKiyoko Jul 14, 2025
b3fb326
implemented: Select DOM element that displays the remaining time for …
CatchingKiyoko Jul 14, 2025
192ccee
implemented: convert user input into a number
CatchingKiyoko Jul 14, 2025
273cafc
fix: correct typo in number conversion for user input
CatchingKiyoko Jul 14, 2025
5fe19ee
implemented: add function to format and update time display in setAlarm
CatchingKiyoko Jul 14, 2025
3c31af3
added: Ensure countdown timer displays two-digit minutes and seconds …
CatchingKiyoko Jul 14, 2025
21f33e2
implemented: call updatedTime function to display initial countdown time
CatchingKiyoko Jul 15, 2025
b0c3c0c
fix: validate user input for positive number in setAlarm function
CatchingKiyoko Jul 15, 2025
f3f61ed
fixed typo error with isNaN
CatchingKiyoko Jul 15, 2025
7b868a2
corrected typo for textContext to textContent
CatchingKiyoko Jul 15, 2025
a8fb6fb
fix: clear existing interval before starting a new countdown timer an…
CatchingKiyoko Jul 16, 2025
28b9e82
fix: clear existing interval before starting a new countdown timer an…
CatchingKiyoko Jul 16, 2025
f958c48
fix: ensure countdown timer clears interval and displays "times up!" …
CatchingKiyoko Jul 16, 2025
e07ee1c
fix: clarify return statement for "times up!" message in countdown timer
CatchingKiyoko Jul 16, 2025
92bbd26
fix: correct interval closure in setAlarm function to correctly run f…
CatchingKiyoko Jul 16, 2025
3c99f1c
fix: ensure alarm plays when countdown reaches zero
CatchingKiyoko Jul 16, 2025
78e82d8
fix: add comment to clarify interval update frequency in setAlarm fun…
CatchingKiyoko Jul 16, 2025
f617770
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko Jul 24, 2025
587b3f1
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko Oct 25, 2025
79db61d
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko Nov 1, 2025
2e30b5d
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko Nov 22, 2025
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
48 changes: 47 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
function setAlarm() {}
function setAlarm() {
Copy link

Choose a reason for hiding this comment

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

There is a bug in your program, suppose the user clicks on the Set Alarm button while the previous alarm is running.

  • Why does that happen?
  • How would you resolve this?

// get the users input in seconds from the input element
const inputField = document.getElementById("alarmSet");

// get the "timeRemaining" element where we show the time
const timeDisplay = document.getElementById("timeRemaining");

// convert the users input to a number
let secondsRemaining = Number(inputField.value);

// check if input is not a number or less than or equal to zero and informs the user to enter a positive number
if (isNaN(secondsRemaining) || secondsRemaining <= 0){
timeDisplay.textContent = "Enter a positive number.";
return;
}

// format and update the time display with a function
function updatedTime(){
// calculate the number into minutes and seconds
const minutes = Math.floor(secondsRemaining / 60);
const seconds = secondsRemaining % 60;

// pad the numbers to ensure double digits so it looks right and is easily readable
const formattedTime = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
timeDisplay.textContent = `Time Remaining: ${formattedTime}`;

}
updatedTime() // shows the starting time

let intervalId; // store a global variable to the interval so we can clear it later

// Start the countdown interval
intervalId = setInterval(() => {

// decrement the number to reduce the countdown
secondsRemaining--;

// check if the timer has reached 0
if (secondsRemaining < 0){
clearInterval(intervalId); // clear the interval when timer reaches 0
timeDisplay.textContent = "times up!" // returns times up when timer reaches 0
return playAlarm();
} else {
updatedTime();
}
}, 1000); // updates the function by running it every 1000ms
Copy link

Choose a reason for hiding this comment

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

Here, 1000 is what we call a magic number (a value whose meaning isn't immediately obvious). How could you make this number's purpose clearer to someone reading your code?

}

// 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