diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..212800ccf 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,28 @@ -function setAlarm() {} +let myTimer; +function setAlarm() { + // fist need to get the input from the id=alarmset + let setTimeSeconds = document.getElementById("alarmSet").value; + console.log(setTimeSeconds); + myTimer = setInterval(() => { + const minutes = Math.trunc(setTimeSeconds / 60); + const seconds = setTimeSeconds % 60; + console.log(minutes); + // then update time remaining whith the value of alarm set + const upDate = document.getElementById("timeRemaining"); + // Time Remaining: 00:00 + upDate.innerHTML = `Time Remaining: ${minutes + .toString() + .padStart(2, "0")}: ${seconds.toString().padStart(2, "0")}`; + // Check if we get to zero + if (setTimeSeconds <= 0) { + playAlarm(); + clearInterval(myTimer); + } + // need tomake the functon counting donw seconds by one until get 00:00 + setTimeSeconds = setTimeSeconds - 1; + }, 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..ff2d3b453 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app