11let countdown ;
22
33function setAlarm ( ) {
4- let seconds = parseInt ( document . getElementById ( "alarmSet" ) . value ) ;
5-
64 clearInterval ( countdown ) ;
7- updateDisplay ( seconds ) ;
5+ document . body . style . backgroundColor = "white" ;
86
9- countdown = setInterval ( ( ) => {
10- seconds -- ;
7+ let inputTime = Number ( document . getElementById ( "alarmSet" ) . value ) ;
8+
9+ if ( isNaN ( inputTime ) || inputTime <= 0 ) {
10+ alert ( "Please type or select your time 👇⏰" ) ;
11+ return ;
12+ }
1113
12- updateDisplay ( seconds ) ;
14+ updateDisplay ( inputTime ) ;
15+
16+ countdown = setInterval ( ( ) => {
17+ inputTime -- ;
1318
14- if ( seconds <= 0 ) {
19+ if ( inputTime <= 0 ) {
1520 clearInterval ( countdown ) ;
21+ updateDisplay ( 0 ) ;
1622 playAlarm ( ) ;
23+
24+ let repetitions = 0 ;
25+ countdown = setInterval ( ( ) => {
26+ document . body . style . backgroundColor = `rgb(
27+ ${ Math . floor ( Math . random ( ) * 256 ) } ,
28+ ${ Math . floor ( Math . random ( ) * 256 ) } ,
29+ ${ Math . floor ( Math . random ( ) * 256 ) } )` ;
30+ repetitions ++ ;
31+
32+ if ( repetitions > 100 ) {
33+ clearInterval ( countdown ) ;
34+ }
35+ } , 200 ) ;
36+ } else {
37+ updateDisplay ( inputTime ) ;
1738 }
1839 } , 1000 ) ;
1940}
@@ -29,8 +50,6 @@ function updateDisplay(seconds) {
2950 document . getElementById ( "timeRemaining" ) . innerText = display ;
3051}
3152
32-
33-
3453// DO NOT EDIT BELOW HERE
3554
3655let audio = new Audio ( "assets/trebolClan.mp3" ) ;
@@ -54,8 +73,7 @@ function pauseAlarm() {
5473 audio . pause ( ) ;
5574 stopAudio . play ( ) ;
5675 clearInterval ( countdown ) ;
76+ // document.body.style.backgroundColor = "white";
5777}
5878
5979window . onload = setup ;
60-
61-
0 commit comments