| 4 | |
| 5 | // this |
| 6 | class Car { |
| 7 | constructor(name, color, topSpeed) { |
| 8 | // properties |
| 9 | this.name = name |
| 10 | this.color = color |
| 11 | this.topSpeed = topSpeed |
| 12 | this.currentSpeed = 0; |
| 13 | } |
| 14 | |
| 15 | // getters & setters |
| 16 | getCurrentSpeed() { |
| 17 | return currentSpeed |
| 18 | } |
| 19 | |
| 20 | zeroToSixty() { |
| 21 | setTimeout(() => { |
| 22 | console.log('pHEW! That was fast!') |
| 23 | this.currentSpeed = 60; |
| 24 | console.log(this.currentSpeed) |
| 25 | }, 3000) |
| 26 | } |
| 27 | |
| 28 | drive(speed=10) { |
| 29 | // console.log('just drove 2 miles!') |
| 30 | this.currentSpeed += speed |
| 31 | console.log(`driving speed at ${this.currentSpeed} mph`) |
| 32 | } |
| 33 | |
| 34 | brake() { |
| 35 | console.log('braking!') |
| 36 | this.currentSpeed -= 10 |
| 37 | } |
| 38 | |
| 39 | stop() { |
| 40 | console.log('coming to a screeching halt!') |
| 41 | this.currentSpeed = 0 |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // porsche, 'yellow', 250 |
| 46 |
nothing calls this directly
no outgoing calls
no test coverage detected