-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmealmaker.js
71 lines (62 loc) · 1.83 KB
/
mealmaker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const menu = {
_courses: {
_appetizers: [],
_mains: [],
_desserts: [],
get appetizers() {
return this._appetizers;
},
set appetizers(appetizers) {
this._appetizers = appetizers;
},
get mains() {
return this._mains;
},
set mains(mains) {
this._mains = mains;
},
get desserts() {
return this._desserts;
},
set desserts(desserts) {
this._desserts = desserts;
}
},
get courses() {
return {
appetizers: this._courses.appetizers,
mains: this._courses.mains,
desserts: this._courses.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice) {
let dish = {
name: dishName,
price: dishPrice
};
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
let dishes = this._courses[courseName];
let index = Math.floor(Math.random() * dishes.length);
return dishes[index];
},
getRandomMeal() {
let appetizer = this.getRandomDishFromCourse('appetizers');
let main = this.getRandomDishFromCourse('mains');
let dessert = this.getRandomDishFromCourse('desserts');
const price = Math.round((appetizer.price+main.price+dessert.price) *100) / 100;
return `Total price of ${appetizer.name}, ${main.name}, ${dessert.name} is ${price}`
}
};
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);
menu.addDishToCourse('appetizers', 'Calamari', 7.99);
menu.addDishToCourse('appetizers', 'Chips and Salsa', 5.99);
menu.addDishToCourse('mains', 'Chicken', 15.99);
menu.addDishToCourse('mains', 'Steak', 19.99);
menu.addDishToCourse('mains', 'Salmon', 24.99);
menu.addDishToCourse('desserts', 'Cake', 4.99);
menu.addDishToCourse('desserts', 'Pie', 5.99);
menu.addDishToCourse('desserts', 'Coffee', 2.99);
const meal = menu.getRandomMeal();
console.log(meal);