You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionupdateHeading(totalSeconds){// Update the heading with the formatted time remaining
11
+
constheading=document.getElementById("timeRemaining");// Get the heading element using its DOM ID
12
+
heading.innerText=`Time Remaining: ${formatTime(totalSeconds)}`;// Set the text of the heading to show the time remaining in the format "Time Remaining: MM:SS"
13
+
}
14
+
15
+
functionsetAlarm(){
16
+
constinput=document.getElementById("alarmSet");// Get the input element using its DOM ID
17
+
letremainingSeconds=Number(input.value);// Convert the input value to a number representing the total seconds for the countdown
18
+
19
+
if(!Number.isFinite(remainingSeconds)||remainingSeconds<0){// Check if the input is a valid number and non-negative
20
+
remainingSeconds=0;// If the input is invalid, set remainingSeconds to 0
21
+
}
22
+
23
+
if(countdownId!==null){// If there is an existing countdown, clear it before starting a new one
24
+
25
+
clearInterval(countdownId);
26
+
}
27
+
28
+
updateHeading(remainingSeconds);// Update the heading to show the initial time remaining before starting the countdown
29
+
30
+
countdownId=setInterval(()=>{// Start a new interval that will execute the provided function every 1000 milliseconds (1 second)
31
+
remainingSeconds-=1;
32
+
33
+
if(remainingSeconds<=0){// If the remaining seconds reach 0 or below, stop the countdown and play the alarm
0 commit comments