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] 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 @@ -
- - - -