File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 11function setAlarm ( ) { }
2+ // Only define Audio if it doesn't exist (Node environment)
3+ if ( typeof Audio === "undefined" ) {
4+ global . Audio = class {
5+ constructor ( src ) {
6+ this . src = src ;
7+ }
8+ play ( ) { }
9+ pause ( ) { }
10+ } ;
11+ }
12+
13+ let intervalId ;
14+
15+ const formatTime = ( s ) => {
16+ const mins = Math . floor ( s / 60 ) ;
17+ const secs = s % 60 ;
18+ return `${ String ( mins ) . padStart ( 2 , "0" ) } :${ String ( secs ) . padStart ( 2 , "0" ) } ` ;
19+ } ;
20+
21+ function setAlarm ( ) {
22+ const input = document . getElementById ( "alarmSet" ) ;
23+ const timer = document . getElementById ( "timeRemaining" ) ;
24+
25+ const seconds = parseInt ( input . value ) ;
26+ if ( isNaN ( seconds ) || seconds < 0 ) return ;
27+
28+ let remaining = seconds ;
29+
30+ // DO NOT EDIT BELOW HERE
31+ timer . textContent = `Time Remaining: ${ formatTime ( remaining ) } ` ;
32+
33+ if ( intervalId ) clearInterval ( intervalId ) ;
34+
35+ intervalId = setInterval ( ( ) => {
36+ remaining -- ;
37+
38+ timer . textContent = `Time Remaining: ${ formatTime ( remaining ) } ` ;
39+
40+ if ( remaining <= 0 ) {
41+ clearInterval ( intervalId ) ;
42+ playAlarm ( ) ;
43+ }
44+ } , 1000 ) ;
45+ }
246
347// DO NOT EDIT BELOW HERE
448
You can’t perform that action at this time.
0 commit comments