diff --git a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..544ff25 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js +++ b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,31 @@ -function setAlarm() {} +function setAlarm() { + let inputValue = document.getElementById("alarmSet").value; + let remainingTime = document.getElementById("timeRemaining"); + + let min = Math.floor(inputValue / 60); + let sec = inputValue % 60; + + let bgClock = document.querySelector(".centre"); + let colorForBg = ["blue", "red", "green", "pink"]; + + let interval = setInterval(() => { + remainingTime.textContent = `Time Remaining: ${min}:${sec}`; + if (sec === 0) { + sec = 60; + min--; + } + sec--; + + if (min < 0) { + playAlarm(); + clearInterval(interval); + setInterval(() => { + bgClock.style.backgroundColor = + colorForBg[Math.floor(Math.random() * colorForBg.length)]; + }, 500); + } + }, 1000); +} // DO NOT EDIT BELOW HERE diff --git a/Week-3/Homework/mandatory/1-alarmclock/index.html b/Week-3/Homework/mandatory/1-alarmclock/index.html index ab7d582..a149aa2 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/index.html +++ b/Week-3/Homework/mandatory/1-alarmclock/index.html @@ -9,7 +9,7 @@ integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" /> - +
@@ -25,4 +25,4 @@