-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBusExample1.js
More file actions
37 lines (32 loc) · 1.12 KB
/
BusExample1.js
File metadata and controls
37 lines (32 loc) · 1.12 KB
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
// "constructor"
// Bus Class: This is the blueprint for a Bus
function Bus(maxSeats) {
this.passengers = 0;
this.seats = maxSeats;
}
Bus.prototype.hopOnTheBus = function() {
const SOCIAL_DISTANCING_THRESHOLD = 0.5;
if(this.passengers < this.seats * SOCIAL_DISTANCING_THRESHOLD) {
console.log("get on!");
this.passengers = this.passengers + 1;
} else {
console.log("sorry we don't have any seats.");
}
}
Bus.prototype.displayPassengerCount = function() {
console.log(`We have ${this.passengers} passengers on board`);
}
const magicBusfallowfieldToCityCentre = new Bus(20);
magicBusfallowfieldToCityCentre.hopOnTheBus();
magicBusfallowfieldToCityCentre.hopOnTheBus();
magicBusfallowfieldToCityCentre.hopOnTheBus();
magicBusfallowfieldToCityCentre.displayPassengerCount();
const oldhamtoCityCentre = new Bus(50);
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.hopOnTheBus();
oldhamtoCityCentre.displayPassengerCount();