From 3ab05e39b2ea6bcd6926ade98e6a3c911f44e3ec Mon Sep 17 00:00:00 2001 From: shaghayeghfar <146011477+shaghayeghfar@users.noreply.github.com> Date: Tue, 4 Nov 2025 17:30:17 +0000 Subject: [PATCH 1/2] alarm clock done --- Sprint-3/alarmclock/alarmclock.js | 31 ++++++++++++++++++++++++-- Sprint-3/alarmclock/index.html | 37 +++++++++++++++++-------------- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..352efe88a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,6 +1,33 @@ -function setAlarm() {} +function setAlarm() { + // get the value from input and show it in the h1 + let input = document.getElementById("alarmSet").value; + let time = Number(input); -// DO NOT EDIT BELOW HERE + document.getElementById( + "timeRemaining" + ).textContent = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + document.title = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + + // start the countdown + const interval = setInterval(() => { + //decress the numnber + time--; + + //update the h1 + document.getElementById( + "timeRemaining" + ).textContent = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + document.title = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + + //make sure just countdown to 0 + if (time <= 0) { + clearInterval(interval); + playAlarm(); + } + }, 1000); +} + +// 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..2ef800b94 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,23 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + Title here + + + +
+

Time Remaining: {00:00}

+ + + + + +
+ + + + \ No newline at end of file From 24bb46dd3d1b6a214a82ecaa0d876adca549fc45 Mon Sep 17 00:00:00 2001 From: shaghayeghfar <146011477+shaghayeghfar@users.noreply.github.com> Date: Sun, 16 Nov 2025 17:47:57 +0000 Subject: [PATCH 2/2] make sure the inut is not null --- Sprint-3/alarmclock/alarmclock.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 352efe88a..8085ad428 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -10,19 +10,22 @@ function setAlarm() { // start the countdown const interval = setInterval(() => { - //decress the numnber - time--; - - //update the h1 - document.getElementById( - "timeRemaining" - ).textContent = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; - document.title = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; - - //make sure just countdown to 0 - if (time <= 0) { - clearInterval(interval); - playAlarm(); + //make sure the input is not null + if (input !== "") { + //decress the numnber + time--; + + //update the h1 + document.getElementById( + "timeRemaining" + ).textContent = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + document.title = `Time Remaining: 00:${time.toString().padStart(2, "0")}`; + + //make sure just countdown to 0 + if (time <= 0) { + clearInterval(interval); + playAlarm(); + } } }, 1000); }