Skip to content

Commit 4f69cca

Browse files
committed
Section 20: Stopping the Timer
1 parent 1506cdd commit 4f69cca

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

20-Drawing-Animations/01-timer/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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')
5256
const 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+
// }

20-Drawing-Animations/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)