diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b1..dac10c71b2 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,56 @@ -function setAlarm() {} +let countdownTimer; +let flashTimer; +let currentSeconds; + +function setAlarm() { + clearInterval(countdownTimer); + // fetch seconds input + currentSeconds = Number(document.getElementById("alarmSet").value); + document.body.style.backgroundImage = "url('alarmsethamster.jfif')"; + document.body.style.backgroundPosition = "centre"; + // set time remaining to seconds input + document.getElementById("timeRemaining").textContent = + `Time Remaining: ${formatTime(currentSeconds)}`; + + // handling the interval and alarm end + countdownTimer = setInterval(() => { + currentSeconds = currentSeconds - 1; + + document.getElementById("timeRemaining").textContent = + `Time Remaining: ${formatTime(currentSeconds)}`; + + if (currentSeconds <= 0) { + clearInterval(countdownTimer); + playAlarm(); + document.getElementById("timeRemaining").textContent = + `Time Remaining: 00:00`; + + // img change + document.body.style.backgroundImage = "url('alarmplaysoundhamster.jfif')"; + document.body.style.backgroundPosition = "center"; + + // box turns red + let flashCount = 0; + const box = document.querySelector(".centre"); + flashTimer = setInterval(() => { + box.classList.toggle("red-bg"); + flashCount++ + if (flashCount >= 20){ + clearInterval(flashTimer); + } + }, 500); + } + }, 1000); +} + +function formatTime(totalSeconds) { + // converts the seconds to minutes and seconds and returns "mm:ss" + const convertToMinutes = Math.floor(totalSeconds / 60); + const remainderSeconds = totalSeconds % 60; + const paddedMinutes = String(convertToMinutes).padStart(2, "0"); + const paddedSeconds = String(remainderSeconds).padStart(2, "0"); + return `${paddedMinutes}:${paddedSeconds}`; +} // DO NOT EDIT BELOW HERE @@ -23,3 +75,10 @@ function pauseAlarm() { } window.onload = setup; + +document.getElementById("stop").addEventListener("click", () => { + document.body.style.backgroundImage = "url('alarmsethamster.jfif')"; + document.body.style.backgroundPosition = "center"; + clearInterval(countdownTimer); + clearInterval(flashTimer); +}); \ No newline at end of file diff --git a/Sprint-3/alarmclock/alarmplaysoundhamster.jfif b/Sprint-3/alarmclock/alarmplaysoundhamster.jfif new file mode 100644 index 0000000000..ea0eab44bf Binary files /dev/null and b/Sprint-3/alarmclock/alarmplaysoundhamster.jfif differ diff --git a/Sprint-3/alarmclock/alarmplaysoundhamster.jfif:Zone.Identifier b/Sprint-3/alarmclock/alarmplaysoundhamster.jfif:Zone.Identifier new file mode 100644 index 0000000000..d6c1ec6829 Binary files /dev/null and b/Sprint-3/alarmclock/alarmplaysoundhamster.jfif:Zone.Identifier differ diff --git a/Sprint-3/alarmclock/alarmsethamster.jfif b/Sprint-3/alarmclock/alarmsethamster.jfif new file mode 100644 index 0000000000..ac82471778 Binary files /dev/null and b/Sprint-3/alarmclock/alarmsethamster.jfif differ diff --git a/Sprint-3/alarmclock/alarmsethamster.jfif:Zone.Identifier b/Sprint-3/alarmclock/alarmsethamster.jfif:Zone.Identifier new file mode 100644 index 0000000000..d6c1ec6829 Binary files /dev/null and b/Sprint-3/alarmclock/alarmsethamster.jfif:Zone.Identifier differ diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d99..ff2d3b4532 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b2..f8375a9623 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -1,9 +1,25 @@ +body { + background-image: url('alarmsethamster.jfif'); + background-size: 700px 800px; + background-position: center; + background-repeat: no-repeat; + background-attachment: fixed; + margin: 0; +} + .centre { position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); + background-color: rgba(255, 255, 255, 0.8); + padding: 20px; + border-radius: 10px; +} + +.red-bg { + background-color: rgba(201, 36, 36, 0.9) !important } #alarmSet { @@ -13,3 +29,12 @@ h1 { text-align: center; } + + +#set { + font: serif; +} + +#stop { + font: serif; +} \ No newline at end of file