From e88114777b7b5d45352ea85f1b865cdfd02c89ec Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Wed, 16 Jul 2025 00:42:13 +0300 Subject: [PATCH] sprint_3 alarm clock app --- Sprint-3/alarmclock/alarmclock.js | 25 ++++++++++++++++++++- Sprint-3/alarmclock/index.html | 37 +++++++++++++++++-------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..64a4c5d2b 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,27 @@ -function setAlarm() {} +function setAlarm() { + let timerDom = document.getElementById("timeRemaining"); + let timeInputValue = document.getElementById("alarmSet").value; + setTimer(timerDom, formatTime(timeInputValue)); + let interval = setInterval(function () { + timeInputValue--; + setTimer(timerDom, formatTime(timeInputValue)); + if (timeInputValue == 0) { + playAlarm(); + clearInterval(interval); + } + }, 1000); +} + +function formatTime(seconds) { + let minutes = Math.trunc(seconds / 60); + let remainingSeconds = seconds % 60; + let formattedTime = minutes.toString().padStart(2, '0') + ':' + remainingSeconds.toString().padStart(2, '0'); + return formattedTime; +} + +function setTimer(timerDon, timeInputValue) { + timerDon.textContent = "Time Remaining: " + String(timeInputValue); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..36715d7d9 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,23 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + Alarm clock app + + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + + \ No newline at end of file