File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Timer {
2121 this . tick ( )
2222 // const timer = setInterval(this.tick, 1000)
2323 this . interval = setInterval ( this . tick , 1000 )
24- console . log ( timer ) ;
24+ console . log ( timer )
2525 // function that is built into the browser
2626 // clearInterval(timer)
2727 }
@@ -32,7 +32,11 @@ class Timer {
3232
3333 tick = ( ) => {
3434 console . log ( 'tick' )
35- this . timeRemaining = this . timeRemaining - 1
35+ if ( this . timeRemaining <= 0 ) {
36+ this . pause ( )
37+ } else {
38+ this . timeRemaining = this . timeRemaining - 1
39+ }
3640 }
3741
3842 get timeRemaining ( ) {
@@ -52,10 +56,9 @@ const pauseButton = document.querySelector('#pause')
5256const timer = new Timer ( durationInput , startButton , pauseButton )
5357// timer.start()
5458
55-
5659// version 1
5760// tick = () => {
5861// console.log('tick')
5962// const timeRemaining = parseFloat(this.durationInput.value)
6063// this.durationInput.value = timeRemaining - 1
61- // }
64+ // }
Original file line number Diff line number Diff line change @@ -120,4 +120,20 @@ class Timer {
120120 setTime () {
121121 return this .durationInput = time
122122 }
123- ```
123+ ```
124+
125+ ``` javascript
126+ tick = () => {
127+ console .log (' tick' )
128+ this .timeRemaining = this .timeRemaining - 1
129+ }
130+
131+ get timeRemaining () {
132+ return parseFloat (this .durationInput .value )
133+ }
134+
135+ set timeRemaining (time ) {
136+ this .durationInput .value = time
137+ }
138+ ```
139+ ## 6. 14 Stopping the Timer
You can’t perform that action at this time.
0 commit comments