-
Notifications
You must be signed in to change notification settings - Fork 3
/
pizza.js
52 lines (43 loc) · 1.35 KB
/
pizza.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
// Write code which models a pizza as a class.
// Pizza has at least following properties:
// name, toppings, base price for a small pizza.
// Pizza has also a function, which calculates
// it’s price.
const extraToppingPrice = 50;
const numberOfFreeToppings = 4;
class Pizza {
name;
toppings = [];
basePrice = 0; // in cents
size = 'S';
constructor(name, toppings, basePrice) {
this.name = name;
this.toppings = toppings;
this.basePrice = basePrice
}
getPrice() {
let extraToppings = this.toppings.length - numberOfFreeToppings;
if (extraToppings < 0) {
extraToppings = 0;
}
return this.basePrice + extraToppings * extraToppingPrice;
}
}
// Write code which models an order to a pizza place as a class.
// The order has a customer name, delivery type,
// and there can be several pizzas in one order.
// Order can be updated by adding pizzas to it with a method of the order class.
class PizzaOrder {
customerName = '';
deliveryType = 'EAT_IN'; // other values TAKE_OUT, DELIVERY
pizzas = [];
addPizza(pizza) {
this.pizzas.push(pizza);
}
getPrice() {
let totalPrice = 0;
// 1) check delivery type and add delivery fee if needed
// 2) loop over the pizzas and sum up their prices
return totalPrice;
}
}