Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
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 will happen if we don't add a value and click on "set alarm", or we add a negative value?

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.

It should call the alarm immediately. Will fix to handle it softly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, if we click on the set alarm multiple times, we are stacking the timers together, how can we handle it so the timer fully resets?

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.

created a variable outside the function, used clearInterval to refresh the alarm

Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
function setAlarm() {}
function setAlarm() {
const input = document.getElementById('alarmSet');
const heading = document.getElementById('timeRemaining');
let totalSeconds = parseInt(input.value) || 0;

function updateDisplay() {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
heading.innerText = `Time Remaining: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;

if (totalSeconds > 0) {
totalSeconds--;
} else {
playAlarm();
clearInterval(intervalId); // Stop interval after alarm
}
}

updateDisplay(); // Set initial time
const intervalId = setInterval(updateDisplay, 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
7 changes: 6 additions & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"@jest/globals": "^30.3.0",
"jest": "^30.3.0",
"jsdom": "^26.1.0"
}
}
Loading