Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7dcef8d
update JSon file
SuWebOnes Jul 23, 2025
a44d23e
update: installing required jsdom
SuWebOnes Jul 23, 2025
b864e83
up date json file
SuWebOnes Jul 23, 2025
0cc242a
update: title for alarm in index.html
SuWebOnes Jul 23, 2025
2612cde
update: update title in Alarm clock app in alarm/index.html
SuWebOnes Jul 23, 2025
1699cc6
update: code for setting countdown and play audio
SuWebOnes Jul 23, 2025
ac94058
update: json files
SuWebOnes Jul 24, 2025
a356165
update: merge json file
SuWebOnes Jul 25, 2025
370be42
update: fix json package
SuWebOnes Jul 26, 2025
80e3a09
update: fix json
SuWebOnes Jul 26, 2025
2445dcb
update: fix the path at the and put at very top of the line
SuWebOnes Jul 26, 2025
b481be3
update: fix code on Stops alarm sound if it’s still playing, Input va…
SuWebOnes Jul 31, 2025
b925ada
Initial commit: Add package-lock.json for module data groups
SuWebOnes Jul 31, 2025
d2d6856
Refactor: Rename title in reading-list and slideshow index.html files
SuWebOnes Jul 31, 2025
3ffb6fa
feat: Implement basic slideshow functionality
SuWebOnes Jul 31, 2025
58b21bc
feat: Add meta information to slideshow's package.json
SuWebOnes Jul 31, 2025
ef063cb
feat: Implement todo list functionality with deadlines and UI
SuWebOnes Jul 31, 2025
a04a2b6
style: Basic styling for todo list application
SuWebOnes Jul 31, 2025
bca41f2
update: reteach
SuWebOnes Jul 30, 2025
5296d92
update: fix codes to do lists and remove in todo-list/script.js
SuWebOnes Jul 31, 2025
229bf44
update: fix markups including comments for easy to fix in todo-list/html
SuWebOnes Jul 31, 2025
605d475
update: markup with extra like Datepicker input in todo-list/index.html
SuWebOnes Jul 31, 2025
79dac20
update: js code for advanced features including bulk deletion of comp…
SuWebOnes Jul 31, 2025
671b9f8
update: fix package of json
SuWebOnes Jul 30, 2025
531f862
update: reteach
SuWebOnes Jul 30, 2025
bcf3df9
update: fixing json packages
SuWebOnes Jul 30, 2025
0c5c298
Merge branch 'main' into alarmclock
SuWebOnes Aug 2, 2025
86d7e53
update: fix codes to do lists and remove in todo-list/script.js
SuWebOnes Jul 31, 2025
07516dd
update: js code for advanced features including bulk deletion of comp…
SuWebOnes Jul 31, 2025
acd71f3
update JSon file
SuWebOnes Jul 23, 2025
166b442
update: fixing json packages
SuWebOnes Jul 30, 2025
a3819e6
delete duplicated json package
SuWebOnes Aug 2, 2025
0bb8a97
revert package json
SuWebOnes Aug 2, 2025
a4a8e00
update: alarm flash in alarmclock.js
SuWebOnes Aug 2, 2025
1eb93b4
update: add pause resume in index.html
SuWebOnes Aug 2, 2025
ce05dda
t
SuWebOnes Aug 5, 2025
a945107
yu
SuWebOnes Aug 5, 2025
8cf5e58
rv js alr
SuWebOnes Aug 7, 2025
209e567
slideshowreverse_rmved_from alarm project
SuWebOnes Aug 7, 2025
a693a1c
revert and resolve conflict
SuWebOnes Aug 8, 2025
c81a944
rem col
SuWebOnes Aug 8, 2025
3aa4e2a
resting jspak
SuWebOnes Aug 8, 2025
8ecb32f
syntax
SuWebOnes Aug 8, 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
131 changes: 119 additions & 12 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,132 @@
function setAlarm() {}
let timeRemaining = 0;
let intervalId;
const audio = new Audio("alarmsound.mp3");

// DO NOT EDIT BELOW HERE
/**
* Sets the alarm countdown.
* Validates input, resets alarm and timer.
*/
function setAlarm() {
const input = document.getElementById("alarmSet");
timeRemaining = parseInt(input.value, 10);

var audio = new Audio("alarmsound.mp3");
// Validation: check for valid number
if (isNaN(timeRemaining) || timeRemaining <= 0) {
alert("Please enter a positive number of seconds.");
return;
}

function setup() {
document.getElementById("set").addEventListener("click", () => {
setAlarm();
});
// Clear any existing countdown
if (intervalId) {
clearInterval(intervalId);
}

// Pause any currently playing alarm sound
pauseAlarm(true);

// Update the initial time display
updateTimeDisplay();

// Start new interval countdown
intervalId = setInterval(() => {
timeRemaining--;
updateTimeDisplay();

document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
});
if (timeRemaining <= 0) {
clearInterval(intervalId);
playAlarm();
startFlashingBackground(); // Flash background when alarm finishes
}
}, 1000);
}

/**
* Updates the countdown time on screen
*/
function updateTimeDisplay() {
const heading = document.getElementById("timeRemaining");
const minutes = Math.floor(timeRemaining / 60).toString().padStart(2, "0");
const seconds = (timeRemaining % 60).toString().padStart(2, "0");
heading.innerText = `Time Remaining: ${minutes}:${seconds}`;
}

/**
* Plays the alarm sound from beginning
*/
function playAlarm() {
audio.currentTime = 0;
audio.play();
}

function pauseAlarm() {
/**
* Stops the alarm sound
* @param {boolean} resetAudio - if true, reset to start
*/
function pauseAlarm(resetAudio = false) {
audio.pause();
if (resetAudio) {
audio.currentTime = 0;
}
}

/**
* Flashes the background color when alarm finishes
*/
function startFlashingBackground() {
let flashCount = 0;
const maxFlashes = 10; // Number of flashes (5 times)
const originalColor = document.body.style.backgroundColor;
const flashInterval = setInterval(() => {
document.body.style.backgroundColor =
document.body.style.backgroundColor === "red" ? "white" : "red";
flashCount++;
if (flashCount >= maxFlashes) {
clearInterval(flashInterval);
document.body.style.backgroundColor = originalColor;
}
}, 300);
}

/**
* Pauses the countdown timer
*/
function pauseTimer() {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
}

/**
* Resumes the countdown timer
*/
function resumeTimer() {
if (!intervalId && timeRemaining > 0) {
intervalId = setInterval(() => {
timeRemaining--;
updateTimeDisplay();

if (timeRemaining <= 0) {
clearInterval(intervalId);
playAlarm();
startFlashingBackground();
}
}, 1000);
}
}

/**
* Setup event listeners after page load
*/
function setup() {
// Set alarm button
document.getElementById("set").addEventListener("click", setAlarm);
// Stop alarm button
document.getElementById("stop").addEventListener("click", () => pauseAlarm(true));
// Pause timer button
document.getElementById("pause").addEventListener("click", pauseTimer);
// Resume timer button
document.getElementById("resume").addEventListener("click", resumeTimer);
}

window.onload = setup;
window.onload = setup;
1 change: 1 addition & 0 deletions Sprint-3/alarmclock/alarmclock.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
*/
require('@testing-library/jest-dom');

const path = require("path");
const { JSDOM } = require("jsdom");
Expand Down
6 changes: 4 additions & 2 deletions 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 All @@ -14,7 +14,9 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
<button id="pause" type="button">Pause</button>
<button id="resume" type="button">Resume</button>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
</html>
Loading
Loading