From bc18306452decd70fc115c90b35baea769a992f0 Mon Sep 17 00:00:00 2001 From: AdnaanA Date: Sat, 12 Jul 2025 12:11:34 +0100 Subject: [PATCH 1/4] modified: Sprint-3/alarmclock/alarmclock.js modified: Sprint-3/alarmclock/index.html --- Sprint-3/alarmclock/alarmclock.js | 25 ++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..ed079d681 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,28 @@ -function setAlarm() {} +function setAlarm() { + const input = document.getElementById("alarmSet"); + let seconds = Number(input.value); + updateAlarmDisplay(seconds); + // Set a timeout to play the alarm after the specified seconds + // Note: This will not work if the page is closed or refreshed] + countdownInterval = setInterval(() => { + seconds--; + if (seconds <= 0) { + clearInterval(countdownInterval); + updateAlarmDisplay(0); + playAlarm(); + } else { + updateAlarmDisplay(seconds); + } + }, 1000); +} + +function updateAlarmDisplay(seconds) { + const display = document.getElementById("timeRemaining"); + const minutes = Math.floor(seconds / 60).toString().padStart(2, '0'); + const secs = (seconds % 60).toString().padStart(2, '0'); + display.textContent = `Time Remaining: ${minutes}:${secs}`; +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..f216bb2a0 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + alarmclock
From 5ab2b60ff4b18326b25c45ff0ddc6805f7b54d11 Mon Sep 17 00:00:00 2001 From: AdnaanA Date: Sat, 12 Jul 2025 12:37:51 +0100 Subject: [PATCH 2/4] modified: Sprint-3/quote-generator/index.html modified: Sprint-3/quote-generator/quotes.js --- Sprint-3/quote-generator/index.html | 2 +- Sprint-3/quote-generator/quotes.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..5f6a720f1 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,7 +3,7 @@ - Title here + Quote generator app diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..98a32557a 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -491,3 +491,15 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote + +// This function will display a random quote in the HTML +function showRandomQuote() { + const randomQuote = pickFromArray(quotes); + document.getElementById("quote").textContent = `"${randomQuote.quote}"`; + document.getElementById("author").textContent = `— ${randomQuote.author}`; +} +// Call the function to display a random quote when the page loads +showRandomQuote(); + +// Setup function to attach event listener +document.getElementById("new-quote").addEventListener("click", showRandomQuote); From f6971e91886352d3cf6800b61be872a8171470e3 Mon Sep 17 00:00:00 2001 From: AdnaanA Date: Sat, 12 Jul 2025 15:37:47 +0100 Subject: [PATCH 3/4] modified: Sprint-3/quote-generator/quotes.js --- Sprint-3/quote-generator/quotes.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 98a32557a..4a4d04b72 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -491,15 +491,3 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote - -// This function will display a random quote in the HTML -function showRandomQuote() { - const randomQuote = pickFromArray(quotes); - document.getElementById("quote").textContent = `"${randomQuote.quote}"`; - document.getElementById("author").textContent = `— ${randomQuote.author}`; -} -// Call the function to display a random quote when the page loads -showRandomQuote(); - -// Setup function to attach event listener -document.getElementById("new-quote").addEventListener("click", showRandomQuote); From 81209f5b01fb0b8a2927dcd10df3d7b2de084a24 Mon Sep 17 00:00:00 2001 From: AdnaanA Date: Mon, 14 Jul 2025 12:54:20 +0100 Subject: [PATCH 4/4] modified: Sprint-3/alarmclock/alarmclock.js --- Sprint-3/alarmclock/alarmclock.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ed079d681..3ff435951 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,11 +1,15 @@ +let countdownInterval; + function setAlarm() { const input = document.getElementById("alarmSet"); let seconds = Number(input.value); updateAlarmDisplay(seconds); - // Set a timeout to play the alarm after the specified seconds - // Note: This will not work if the page is closed or refreshed] - countdownInterval = setInterval(() => { + + // Clear any existing interval + clearInterval(countdownInterval); + + countdownInterval = window.setInterval(() => { seconds--; if (seconds <= 0) { clearInterval(countdownInterval); @@ -19,10 +23,15 @@ function setAlarm() { function updateAlarmDisplay(seconds) { const display = document.getElementById("timeRemaining"); - const minutes = Math.floor(seconds / 60).toString().padStart(2, '0'); - const secs = (seconds % 60).toString().padStart(2, '0'); + const minutes = Math.floor(seconds / 60) + .toString() + .padStart(2, "0"); + const secs = (seconds % 60).toString().padStart(2, "0"); display.textContent = `Time Remaining: ${minutes}:${secs}`; } + +window.setAlarm = setAlarm; +window.updateAlarmDisplay = updateAlarmDisplay; // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3");