From 439144a59379aa3aae349bbcca9d6048d1f5f7a1 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Wed, 13 May 2026 15:03:30 +0100 Subject: [PATCH 1/6] added convertTime function --- Sprint-3/alarmclock/alarmclock.js | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..5ab0b8db6 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,34 @@ -function setAlarm() {} +function setAlarm() { + timeRemaining = document.getElementById("timeRemaining") + alarmSet = document.getElementById("alarmSet").value + + + + + timeRemaining.textContent = `Time Remaining: ${remainingMinutes}:${remainingSeconds}` +} + +function countdown(time) { + setInterval(() => { + + }, 1000) +} + +function convertTime(timeSeconds) { + if (timeSeconds > 5999) {return [99, 59]}; + const seconds = timeSeconds % 60; + const minutes = (timeSeconds - seconds) / 60; + console.log([minutes, seconds]) + return [minutes, seconds]; +} + +convertTime(5000000) +convertTime(50) +convertTime(500) +convertTime(5000000) + +/* // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); @@ -23,3 +52,4 @@ function pauseAlarm() { } window.onload = setup; +*/ \ No newline at end of file From 2fa60e6337e6f45508c77c3e747b86978dd78318 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Wed, 13 May 2026 15:15:49 +0100 Subject: [PATCH 2/6] added printTim function --- Sprint-3/alarmclock/alarmclock.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 5ab0b8db6..4f379c410 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,7 +1,7 @@ function setAlarm() { timeRemaining = document.getElementById("timeRemaining") - alarmSet = document.getElementById("alarmSet").value - + timeSet = document.getElementById("alarmSet").value + const time = convertTime(timeSet) @@ -11,7 +11,7 @@ function setAlarm() { function countdown(time) { setInterval(() => { - + }, 1000) } @@ -23,6 +23,16 @@ function convertTime(timeSeconds) { return [minutes, seconds]; } +function printTime(time) { + const paddedHours = String(time[0]).padStart(2, "0"); + const paddedSeconds = String(time[1]).padStart(2, "0"); + return paddedHours + ":" + paddedSeconds; +} + +printTime([50,40]) +printTime([50,4]) +printTime([5,40]) + convertTime(5000000) convertTime(50) convertTime(500) From 0dfe10c689b2956734bbcf3b3e6ac16e1751a3d4 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Wed, 13 May 2026 16:18:10 +0100 Subject: [PATCH 3/6] code complete, all tests passed --- Sprint-3/alarmclock/alarmclock.js | 44 +++++++++++++++++-------------- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 4f379c410..806afb48d 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,22 +1,36 @@ +let timer; + function setAlarm() { - timeRemaining = document.getElementById("timeRemaining") timeSet = document.getElementById("alarmSet").value - const time = convertTime(timeSet) - - - - - timeRemaining.textContent = `Time Remaining: ${remainingMinutes}:${remainingSeconds}` + const time = countdown(timeSet) + if (time > 0) { + countdown(time); + } } function countdown(time) { - setInterval(() => { - + clearInterval(timer); + let timeRemaining = time; + if (timeRemaining > 5999) {timeRemaining = 5999}; + UpdateShownTime(timeRemaining) + + timer = setInterval(() => { + timeRemaining -= 1; + if (timeRemaining == 0 ) {clearInterval(timer); playAlarm();} + UpdateShownTime(timeRemaining) }, 1000) } +function UpdateShownTime(timeRemaining) { + let timeRemainingOutput = document.getElementById("timeRemaining"); + let title = document.getElementById("title"); + const formattedTime = convertTime(timeRemaining); + const printedTime = printTime(formattedTime); + timeRemainingOutput.textContent = `Time Remaining: ${printedTime}`; + title.textContent = `Time Remaining: ${printedTime}`; +} + function convertTime(timeSeconds) { - if (timeSeconds > 5999) {return [99, 59]}; const seconds = timeSeconds % 60; const minutes = (timeSeconds - seconds) / 60; console.log([minutes, seconds]) @@ -29,16 +43,7 @@ function printTime(time) { return paddedHours + ":" + paddedSeconds; } -printTime([50,40]) -printTime([50,4]) -printTime([5,40]) - -convertTime(5000000) -convertTime(50) -convertTime(500) -convertTime(5000000) -/* // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); @@ -62,4 +67,3 @@ function pauseAlarm() { } window.onload = setup; -*/ \ No newline at end of file diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..075ae1c58 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock app
From ace2ae8009ad0d5e402d12defc1364aff30c90ee Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Wed, 13 May 2026 16:49:25 +0100 Subject: [PATCH 4/6] styled with prettier --- Sprint-3/alarmclock/alarmclock.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 806afb48d..43d0d1a92 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,8 +1,8 @@ let timer; function setAlarm() { - timeSet = document.getElementById("alarmSet").value - const time = countdown(timeSet) + timeSet = document.getElementById("alarmSet").value; + const time = countdown(timeSet); if (time > 0) { countdown(time); } @@ -11,14 +11,19 @@ function setAlarm() { function countdown(time) { clearInterval(timer); let timeRemaining = time; - if (timeRemaining > 5999) {timeRemaining = 5999}; - UpdateShownTime(timeRemaining) - + if (timeRemaining > 5999) { + timeRemaining = 5999; + } + UpdateShownTime(timeRemaining); + timer = setInterval(() => { timeRemaining -= 1; - if (timeRemaining == 0 ) {clearInterval(timer); playAlarm();} - UpdateShownTime(timeRemaining) - }, 1000) + if (timeRemaining == 0) { + clearInterval(timer); + playAlarm(); + } + UpdateShownTime(timeRemaining); + }, 1000); } function UpdateShownTime(timeRemaining) { @@ -33,7 +38,7 @@ function UpdateShownTime(timeRemaining) { function convertTime(timeSeconds) { const seconds = timeSeconds % 60; const minutes = (timeSeconds - seconds) / 60; - console.log([minutes, seconds]) + console.log([minutes, seconds]); return [minutes, seconds]; } @@ -43,7 +48,6 @@ function printTime(time) { return paddedHours + ":" + paddedSeconds; } - // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); From d14f6960e60d8b17758cc21f3c592da31c7e2307 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Thu, 14 May 2026 17:52:41 +0100 Subject: [PATCH 5/6] pull request reviewed changes made --- Sprint-3/alarmclock/alarmclock.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 43d0d1a92..c5a68e459 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,11 +1,8 @@ let timer; function setAlarm() { - timeSet = document.getElementById("alarmSet").value; + const timeSet = document.getElementById("alarmSet").value; const time = countdown(timeSet); - if (time > 0) { - countdown(time); - } } function countdown(time) { @@ -14,7 +11,7 @@ function countdown(time) { if (timeRemaining > 5999) { timeRemaining = 5999; } - UpdateShownTime(timeRemaining); + updateShownTime(timeRemaining); timer = setInterval(() => { timeRemaining -= 1; @@ -22,11 +19,11 @@ function countdown(time) { clearInterval(timer); playAlarm(); } - UpdateShownTime(timeRemaining); + updateShownTime(timeRemaining); }, 1000); } -function UpdateShownTime(timeRemaining) { +function updateShownTime(timeRemaining) { let timeRemainingOutput = document.getElementById("timeRemaining"); let title = document.getElementById("title"); const formattedTime = convertTime(timeRemaining); From c69782f8def1317eaed04ea5fb5da84d66669b40 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Thu, 14 May 2026 18:07:09 +0100 Subject: [PATCH 6/6] pr review const declaration removed --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index c5a68e459..b9f1f1f58 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -2,7 +2,7 @@ let timer; function setAlarm() { const timeSet = document.getElementById("alarmSet").value; - const time = countdown(timeSet); + countdown(timeSet); } function countdown(time) {