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