-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmealMaker.js
75 lines (70 loc) · 2.28 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
72
73
74
let menu = {
_courses : {
appetizers:[],
mains:[],
desserts:[],
},
get courses(){
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},
//Getter and Setter
get appetizers(){
return this._courses.appetizers;
},
get mains(){
return this._courses.mains;
},
get desserts(){
return this._courses.desserts;
},
set appetizers(appetizerIn){
this._courses.appetizers = appetizerIn;
},
set mains(mainIn){
this._courses.mains = mainIn;
},
set desserts(dessertsIn){
this._courses.desserts = dessertsIn;
},
// Methods
addDishToCourse(courseName,dishName,dishPrice){
const dish={
name:dishName,
price:dishPrice
};
//console.log(this._courses[courseName]);
this._courses[courseName].push(dish);
//How to use setter method in this case?
},
getRandomDishFromCourse(courseName){
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[randomIndex];
},
generateRandomMeal(){
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomDishFromCourse('desserts');
const totalPrice = appetizer.price + main.price + dessert.price;
return`Today's Meal : ${appetizer.name}, ${main.name}, ${dessert.name}, and Total Price is $ ${totalPrice}`;
}
};
// Add at least 3 dishes to each course
menu.addDishToCourse('appetizers', 'Caesar Salad', 7.50);
menu.addDishToCourse('appetizers', 'Chicken Caesar Salad', 8.25);
menu.addDishToCourse('appetizers', 'Butternut Hummus', 6.25);
menu.addDishToCourse('mains', 'Low Carb Turkey-Stuffed Peppers', 27.25);
menu.addDishToCourse('mains', 'Grilled Salmon', 25.00);
menu.addDishToCourse('mains', 'Juicy Roasted Chicken', 27.99);
menu.addDishToCourse('mains', 'Baked BBQ Baby Back Ribs', 31.99);
menu.addDishToCourse('desserts', 'Triamisu', 4.99);
menu.addDishToCourse('desserts', 'Apple and Butterscotch Pie', 12.25);
menu.addDishToCourse('desserts', 'Affogato', 5.79);
menu.addDishToCourse('desserts', 'Amaretto Bruelee', 4.99);
menu.addDishToCourse('desserts', 'Aniseed and Chocolate Parfait', 7.99);
let meal = menu.generateRandomMeal();
console.log(meal);