-
-
Save codecademydev/e9391a74ca7e259b5267924258fba62a to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const menu = { | |
_courses:{ | |
appetizers: [], | |
mains: [], | |
desserts: [], | |
}, | |
get appetizers(){ | |
return this._courses.appetizers | |
}, | |
get mains(){ | |
return this._courses.mains | |
}, | |
get desserts(){ | |
return this._courses.desserts | |
}, | |
set appetizers(appetizers){ | |
this._courses.appetizers = "appetizer"; | |
}, | |
set mains(mains){ | |
this._courses.mains = "main"; | |
}, | |
set desserts(desserts){ | |
this._courses.desserts = "dessert"; | |
}, | |
get courses(){ | |
return { | |
appetizers: this.appetizers, | |
mains: this.mains, | |
desserts: this.desserts | |
}; | |
}, | |
addDishToCourse(courseName, dishName, dishPrice){ | |
const dish = { | |
name: dishName, | |
price: dishPrice | |
}; | |
this._courses[courseName] = dish; | |
}, | |
getRandomDishFromCourse(courseName){ | |
const dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex] | |
}, | |
generateRandomMeal(courseName){ | |
const appetizer = this.getRandomDishFromCourse("appetizers"); | |
const main = this.getRandomDishFromCourse("mains"); | |
const dessert = this.getRandomDishFromCourse("desserts"); | |
const totalPrice = appetizer.price + main.price + dessert.price; | |
return `Your total is $${totalPrice} and your meals are ${appetizer.name}, ${main.name}, ${dessert.name},` | |
} | |
}; | |
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25); | |
let meal = menu.generateRandomMeal() | |
console.log(meal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment