-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestaurantExample.js
More file actions
50 lines (39 loc) · 1.11 KB
/
Copy pathrestaurantExample.js
File metadata and controls
50 lines (39 loc) · 1.11 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
38
39
40
41
42
43
44
45
46
47
48
49
50
const Order = require("./Order");
const Item = require("./Item");
class Restaurant {
constructor(name) {
this.name = name;
this.orders = [];
this.revenue = 0;
}
takeOrder(order) {
this.revenue += order.item.price;
this.orders.push(order);
console.log(`Added #${order.id} to the queue`);
this.printRevenue();
}
printRevenue() {
console.log(`${this.name} has made ${this.revenue} so far!`);
}
prepareOrders() {
const prepareInterval = setInterval(() => {
if (this.orders.length === 0) {
console.log("Finished cooking all orders!");
clearInterval(prepareInterval);
} else {
const order = this.orders.shift();
console.log(`#${order.id} has been prepared.`);
}
}, 1000);
}
}
const restaurant = new Restaurant("Nandos");
const restaurant2 = new Restaurant("Mcdonarasdl;fijdsfklujg");
const items = [
new Item("Chicken Burger", 5.99),
new Item("Drink", 3.5),
new Item("Chips", 2.0)
];
const orders = items.map(item => new Order(item));
orders.forEach(order => restaurant.takeOrder(order));
restaurant.prepareOrders();