-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path38-round-trip.js
57 lines (53 loc) · 1.26 KB
/
38-round-trip.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
48
49
50
51
52
53
54
55
56
57
// Round Trip ✈️
// Codédex
const departTripTicket = {
name: "Brandon",
from: "Pittsburgh, PA",
to: "Augsburg, Germany",
businessClass: false,
upgrade() {
if (this.businessClass) {
console.log("Your ticket is already business class!");
} else {
this.businessClass = true;
console.log("Ticket upgraded to business class!");
}
},
leaveTime: 12,
arriveTime: 23,
flightTime() {
let flightTime = this.arriveTime - this.leaveTime;
if (flightTime < 0) {
flightTime += 24;
}
console.log(flightTime + " hours");
}
};
const returnTripTicket = {
name: "Brandon",
from: "Augsburg, Germany",
to: "Pittsburgh, PA",
businessClass: true,
upgrade() {
if (this.businessClass) {
console.log("Your ticket is already business class!");
} else {
this.businessClass = true;
console.log("Ticket upgraded to business class!");
}
},
leaveTime: 24,
arriveTime: 4,
flightTime() {
let flightTime = this.arriveTime - this.leaveTime;
if (flightTime < 0) {
flightTime += 24;
}
console.log(flightTime + " hours");
}
};
// Upgrade and check flight times
departTripTicket.upgrade();
returnTripTicket.upgrade();
departTripTicket.flightTime();
returnTripTicket.flightTime();