-
Notifications
You must be signed in to change notification settings - Fork 0
/
carOOP-challenge.js
47 lines (44 loc) · 1009 Bytes
/
carOOP-challenge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Vehicle {
constructor (a,b,c) {
this.make = a;
this.model = b;
this.year = c;
}
honk() {
console.log('beep');
}
toString() {
console.log(`This bad boy is a ${this.year} ${this.make} ${this.model}`);
}
}
class Car extends Vehicle {
constructor(a,b,c) {
super(a,b,c)
this.numWheels = 4;
}
}
class Motorcycle extends Vehicle {
constructor(a,b,c) {
super(a,b,c);
this.numWheels = 2;
}
revEngine() {
console.log("VROOM!!!")
}
}
class Garage {
constructor(a) {
this.vehicles = [];
this.capacity = a;
}
add(a) {
if (!(a instanceof Vehicle)) {
throw new Error ('Only vehicles are allowed in here!');
}
if (this.vehicles.length >= this.capacity) {
throw new Error ('Sorry, the garage is full.');
}
this.vehicles.push(a);
console.log('Vehicle added to the garage!');
}
}