-
Notifications
You must be signed in to change notification settings - Fork 0
/
mealMaker.js
70 lines (68 loc) · 2.22 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
let menu = {
_courses:
{
appetizer: [],
get appetizers(){return this.appetizer},
set appetizers(z){this.appetizer.push(z)},
main: [],
set mains(y){this.main.push(y)},
get mains(){return this.main},
dessert: [],
set desserts(z){this.dessert.push(z)},
get desserts(){return this.dessert}
},
get courses()
{
return {
appetizers:
this._courses.appetizers,
mains:
this._course.mains,
desserts:
this._course.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
};
//console outputs for some troubleshooting
//console.log(`addDishToCourse checker: ${dish}`);
//console.log('Variables - courseName: ' + courseName + '\n dishName: ' + dishName + '\n dishPrice: ' + dishPrice);
//console.log(`this._courses['appetizers'] checker: ${this._courses['appetizers']}`);
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName)
{
let dishes = this._courses[courseName];
let i = Math.floor(Math.random() * dishes.length);
//console.log(`dishes.length is: ${dishes.length}`);
//console.log(dishes);
return dishes[i];
},
generateRandomMeal() {
const appetizers =
this.getRandomDishFromCourse('appetizers');
const mains =
this.getRandomDishFromCourse('mains');
const desserts =
this.getRandomDishFromCourse('desserts');
console.log(appetizers);
console.log(mains);
console.log(desserts);
const totalPrice = appetizers.price + mains.price + desserts.price;
return `Prepared meal: ${appetizers.name}, ${mains.name}, ${desserts.name}. Total price is ${totalPrice}.`;
}
};
menu.addDishToCourse('appetizers', 'ravioli', 5);
menu.addDishToCourse('appetizers', 'shrimps', 6);
menu.addDishToCourse('appetizers', 'tomatoe soup', 4);
menu.addDishToCourse('mains', 'Beef steak', 15);
menu.addDishToCourse('mains', 'Grilled fish', 12);
menu.addDishToCourse('mains', 'Roasted chicken', 10);
menu.addDishToCourse('desserts', 'icecream', 5);
menu.addDishToCourse('desserts', 'fruity loops', 8);
menu.addDishToCourse('desserts', 'chocolate cake', 10);
let meal = menu.generateRandomMeal();
console.log(meal);