const menu = {
_courses : {
_appetizers : [],
_mains : [],
_desserts : [],
set appetizers (appetizer){
this._appetizers.push(appetizer);
},
set mains (main){
this._mains.push(main);
},
set desserts (dessert){
this._desserts.push(dessert);
},
get appetizers(){
return this._appetizers;
},
get mains(){
return this._mains;
},
get desserts(){
return this._desserts;
}
},
get courses(){
return {
appetizers : this._courses.appetizers,
// 이것은 appetizers getter 메소드를 사용합니다.
mains : this._courses.mains,
// 이것은 mains getter 메소드를 사용합니다.
desserts : this._courses.desserts
// 이것은 desserts getter 메소드를 사용합니다.
}
},
set courses(course){
},
addDishToCourse(courseName, dishName, dishPrice){
const dish = {
name: dishName,
price: dishPrice
};
//this._courses[courseName].push(dish);
this._courses[courseName]= dish;
},
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 `당신의 식사는 ${appetizer.name}, ${main.name}, ${dessert.name} 입니다. 가격은 ${totalPrice}입니다.`;
}
};
menu.addDishToCourse('appetizers', '샐러드', 4.25);
menu.addDishToCourse('appetizers', '과일', 1.25);
menu.addDishToCourse('appetizers', '스프', 5.25);
menu.addDishToCourse('mains', '스테이크', 12.25);
menu.addDishToCourse('mains', '파스타', 8.25);
menu.addDishToCourse('mains', '피자', 15.25);
menu.addDishToCourse('desserts', '쿠키', 1.25);
menu.addDishToCourse('desserts', '주스', 2.64);
menu.addDishToCourse('desserts', '커피', 2.64);
let meal = menu.generateRandomMeal();
console.log(meal);
'Coding' 카테고리의 다른 글
scss _presets.scss (0) | 2018.08.22 |
---|---|
fabric 참고 (0) | 2018.06.21 |
ES6 ::: 배열 (0) | 2018.06.18 |
선택 안됨 Jquery ::: 반복연습 2번째 (0) | 2018.06.12 |
Jquery ::: 반복연습 1번째 (0) | 2018.06.12 |