MCPcopy Create free account
hub / github.com/CleverProgrammers/JavaScript-Course-by-Clever-Programmer- / Car

Class Car

classes/carClass/script.js:6–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5// this
6class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected