diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..5cb7902aa 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,36 @@ -function setAlarm() {} +let countdown; // just to make it avails for later +let isPaused = false; // start off false so the timer is not paused +let timeRemaining; // time remaining in seconds + +function setAlarm() { + const inputField = document.getElementById("alarmSet"); //get input + timeRemaining = parseInt(inputField.value); //set time remaining in seconds + + const updateTitle = () => { + const minutes = String(Math.floor(timeRemaining/60)).padStart(2, '0'); // minutes + const seconds = String(timeRemaining % 60).padStart(2, '0'); // seconds + document.getElementById("timeRemaining").innerText = `Time Remaining: ${minutes}:${seconds}`; + }; + + updateTitle(); + + countdown = setInterval(() => { + if (!isPaused){ + timeRemaining = timeRemaining - 1; + updateTitle(); + + if (timeRemaining <= 0) { + clearInterval(countdown); + playAlarm(); + } + } + }, 1000); +} + +function pauseTimer() { + isPaused = !isPaused; + document.getElementById("pause").innerText = isPaused ? "Resume Timer" : "Pause Timer"; +} // DO NOT EDIT BELOW HERE @@ -12,6 +44,10 @@ function setup() { document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); }); + + document.getElementById("pause").addEventListener("click", () => { + pauseTimer(); + }); } function playAlarm() { diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..dc8078cb5 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
@@ -13,8 +13,9 @@

Time Remaining: 00:00

+
- + \ No newline at end of file