From ed3d3ccf62c6d53b041c1dfb1b84212c3e057102 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 3 Apr 2026 03:04:37 +0100 Subject: [PATCH 1/5] update html title, convert input value to time format and set dynamic alarm counter --- Sprint-3/alarmclock/alarmclock.js | 30 +++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 4 +++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..556a78323 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,32 @@ -function setAlarm() {} +function time_convert(num) { + let minutes = Math.floor((num % 3600) / 60); + let seconds = num % 60; + return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0'); +} +function setAlarm() { + const alarmSetInput = document.getElementById("alarmSet"); + const timer = time_convert(alarmSetInput.value) + const timeRemainingCounter = document.getElementById("timeRemaining"); + timeRemainingCounter.textContent = `Time Remaining: ${timer}`; +} + +// ## How the clock should work + +// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`. + +// Every one second the title should count down by one. + +// When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`. + +// You can stop the alarm sound by pressing the `Stop Alarm` button. + +// ## Need Help? + +// Only read this section if you really need to! It's good to work this out for yourself. + +// ### Hints + +// - Have you tried looking at the `setInterval` function? // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..74fcec95a 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
@@ -18,3 +18,5 @@

Time Remaining: 00:00

+ + From 0d11d749464b54cc32ebe0436859b00491aee10a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 3 Apr 2026 13:11:18 +0100 Subject: [PATCH 2/5] changed html title using js queryselector --- Sprint-3/alarmclock/alarmclock.js | 4 +++- Sprint-3/alarmclock/index.html | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 556a78323..2e2b313ba 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,3 +1,5 @@ +const title = document.querySelector('title') +title.textContent = "Alarm clock app"; function time_convert(num) { let minutes = Math.floor((num % 3600) / 60); let seconds = num % 60; @@ -12,7 +14,7 @@ function setAlarm() { // ## How the clock should work -// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`. +// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`. => Done // Every one second the title should count down by one. diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 74fcec95a..d74c5a886 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Alarm clock app + Title here
@@ -19,4 +19,3 @@

Time Remaining: 00:00

- From 44f98d703df1dcfb34df0206635defdb13755fa3 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 3 Apr 2026 16:14:52 +0100 Subject: [PATCH 3/5] update alarm logic and removed unused comments --- Sprint-3/alarmclock/alarmclock.js | 36 +++++++++++++------------------ 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 2e2b313ba..c5be86732 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -6,29 +6,22 @@ function time_convert(num) { return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0'); } function setAlarm() { - const alarmSetInput = document.getElementById("alarmSet"); - const timer = time_convert(alarmSetInput.value) - const timeRemainingCounter = document.getElementById("timeRemaining"); - timeRemainingCounter.textContent = `Time Remaining: ${timer}`; + const alarmSetInputEl = document.getElementById("alarmSet"); + let timeEl = Number(alarmSetInputEl.value); + const timeRemainingCounterEl = document.getElementById("timeRemaining"); + const interval = setInterval(() => { + timeEl--; + + timeRemainingCounterEl.textContent = `Time Remaining: ${time_convert(timeEl)}`; + + if (timeEl <= 0) { + clearInterval(interval); + timeRemainingCounterEl.textContent = "Done!"; + playAlarm(); + } + }, 1000); } -// ## How the clock should work - -// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`. => Done - -// Every one second the title should count down by one. - -// When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`. - -// You can stop the alarm sound by pressing the `Stop Alarm` button. - -// ## Need Help? - -// Only read this section if you really need to! It's good to work this out for yourself. - -// ### Hints - -// - Have you tried looking at the `setInterval` function? // DO NOT EDIT BELOW HERE @@ -53,3 +46,4 @@ function pauseAlarm() { } window.onload = setup; + From 8c9db65c89ee61f40144da52a242053420f62b3b Mon Sep 17 00:00:00 2001 From: marthak1 Date: Mon, 6 Apr 2026 18:44:50 +0100 Subject: [PATCH 4/5] update htlm title in html file --- Sprint-3/alarmclock/alarmclock.js | 2 -- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index c5be86732..782c92ce1 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,3 @@ -const title = document.querySelector('title') -title.textContent = "Alarm clock app"; function time_convert(num) { let minutes = Math.floor((num % 3600) / 60); let seconds = num % 60; diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index d74c5a886..bffbf369c 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
From 2a0eef7265b260e5a49bf738534be8d45ec86921 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Mon, 6 Apr 2026 20:08:17 +0100 Subject: [PATCH 5/5] function updated to disallow multiple timers and validate input --- Sprint-3/alarmclock/alarmclock.js | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 782c92ce1..c41b5675e 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -3,23 +3,52 @@ function time_convert(num) { let seconds = num % 60; return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0'); } +let currentInterval = null; + +function setup() { + document.getElementById("set").addEventListener("click", setAlarm); + document.getElementById("stop").addEventListener("click", pauseAlarm); +} + function setAlarm() { + if (currentInterval !== null) return; + const alarmSetInputEl = document.getElementById("alarmSet"); - let timeEl = Number(alarmSetInputEl.value); + let timeEl = Number(alarmSetInputEl.value); + if (!Number.isFinite(timeEl) || timeEl <= 0) { + alert("Please enter a valid number greater than 0"); + return; + } const timeRemainingCounterEl = document.getElementById("timeRemaining"); - const interval = setInterval(() => { - timeEl--; + const button = document.getElementById("set"); + + button.disabled = true; + + currentInterval = setInterval(() => { + timeEl--; timeRemainingCounterEl.textContent = `Time Remaining: ${time_convert(timeEl)}`; if (timeEl <= 0) { - clearInterval(interval); + clearInterval(currentInterval); + currentInterval = null; + timeRemainingCounterEl.textContent = "Done!"; playAlarm(); + button.disabled = false; } }, 1000); } +function pauseAlarm() { + if (currentInterval !== null) { + clearInterval(currentInterval); + currentInterval = null; + + document.getElementById("set").disabled = false; + } +} + // DO NOT EDIT BELOW HERE @@ -44,4 +73,3 @@ function pauseAlarm() { } window.onload = setup; -