-
Notifications
You must be signed in to change notification settings - Fork 1
/
main-test.js
executable file
·44 lines (37 loc) · 1002 Bytes
/
main-test.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
const menu ={
_courses : {
_mains : [],
get mainsA () {
return this._mains;
},
set mainsA (mainsIn) {
},
},
get coursesA () {
return {
mainsA : this._courses.mainsA,
}
},
//add Dish to course function
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: courseName,
price: dishPrice,
};
this._courses[courseName].push(dish);
},
// get dish from course function
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random()*dishes.length);
return randomIndex;
},
generateRandomMeal() {
const mainsA = this.getRandomDishFromCourse('mainsA');
const totalPrice = this._courses._mains[mainsA].price ;
return `your meal is ${this._courses._mains[mainsA].name} the price is $${totalPrice}.`;
}
};
menu.addDishToCourse('mainsA', "salad", 5);
let meal = menu.generateRandomMeal();
console.log(meal);