File tree Expand file tree Collapse file tree 1 file changed +56
-1
lines changed
Week-3/Homework/mandatory/1-alarmclock Expand file tree Collapse file tree 1 file changed +56
-1
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ function setAlarm ( ) {
2+
3+ let setAlarmbutton = document . querySelector ( "#set" ) ;
4+ let alarmInputValue = document . querySelector ( "#alarmSet" ) . value ; // this is value in box
5+ setAlarmbutton . addEventListener ( "click" , alarmOn ( alarmInputValue ) ) ;
6+ }
7+
8+ function alarmOn ( inputValue )
9+ {
10+ let time = setInterval ( function ( )
11+ {
12+ if ( inputValue === 0 )
13+ {
14+ clearInterval ( time ) ;
15+ playAlarm ( ) ;
16+ }
17+ updateScreen ( inputValue ) ;
18+ inputValue -- ;
19+ } , 1000 )
20+ }
21+
22+ function updateScreen ( newValue ) {
23+ let timeRemaining = document . querySelector ( "#timeRemaining" ) ; // here we are taking the tag by id
24+ textTime = timeRemaining . textContent ; // refering to the tags textcontent so that we can update later.
25+ let replacementTime = convertTime ( newValue ) ; // this is the variable which will contain the final value in minutes and seconds.
26+ textTime = textTime . slice ( 0 , 15 ) + replacementTime ; // updating the string to put it as textcontent on the page.
27+
28+ timeRemaining . textContent = textTime ;
29+ }
30+
31+
32+ // This will convert input time (initially in seconds) into minutes and seconds format.
33+ function convertTime ( inputValue )
34+ {
35+ var minutes = 0 ;
36+ var seconds = 0 ;
37+
38+ if ( inputValue <= 60 ) {
39+ minutes = 0 ;
40+ seconds = inputValue ;
41+ }
42+ else {
43+ minutes = Math . floor ( inputValue / 60 ) ;
44+ seconds = inputValue - Math . floor ( minutes * 60 ) ;
45+ }
46+
47+ if ( minutes < 10 ) {
48+ minutes = "0" + minutes ;
49+ }
50+ if ( seconds < 10 ) {
51+ seconds = "0" + seconds ;
52+ }
53+
54+ var finalValue = minutes + ":" + seconds ;
55+ return finalValue ;
56+ }
257
358// DO NOT EDIT BELOW HERE
459
You can’t perform that action at this time.
0 commit comments