Hi There!
Here’s the link to the project: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-objects/projects/meal-maker
Would love to get your thoughts. Especially on this bit:
addDishToCourse(courseName,dishName,dishPrice) {
let dish = {
name: dishName,
price: dishPrice
};
this[courseName].push(dish);
I tried to use property value shorthand and I couldn’t get it to work. Is that the right place to use it?
Also, the get courses()
function was requested in the checklist, but doesn’t seem to do anything. Any ideas where I should be using it?
Full Code:
const menu = {
_courses: { //private, should only be mutated with 'set' functions now
appetizers: [],
mains: [],
desserts: []
},
get appetizers(){ // gets and sets are used to create and pull the menu
return this._courses.appetizers;
},
set appetizers(newAppetizer) {
this._courses.appetizers = Object.values(newAppetizer);
},
get mains() {
return this._courses.mains;
},
set mains(newMain) {
this._courses.mains = Object.values(newMain);
},
get desserts() {
return this._courses.desserts;
},
set desserts(newDessert) {
this._courses.desserts = Object.values(newDessert);
},
get courses() { // The instructions require this 'get', but it doesn't seem to do anything...
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},
addDishToCourse(courseName,dishName,dishPrice) { // Creates dishes when called and adds them to the avialable menu
let dish = {
name: dishName,
price: dishPrice
};
this[courseName].push(dish);
},
getRandomDishFromCourse(courseName) { // Selects from the courses loaded when generaing a meal
let dishes = Object.values(this[courseName]);
let randGen = Math.floor(Math.random() * dishes.length);
return dishes[randGen];
},
generateRandomMeal() { // Pulls random dishes for each course
let appetizer = this.getRandomDishFromCourse('appetizers');
let main = this.getRandomDishFromCourse('mains');
let dessert = this.getRandomDishFromCourse('desserts');
let price = appetizer.price + main.price + dessert.price
return `Bon appetite, may I suggest an appetizer of ${appetizer.name}, followed by a declicious main of ${main.name}. Perhaps we could top it off with a dessert of ${dessert.name}? Only £${price}!`
}
}
// Inidividually added menu items
menu.addDishToCourse('appetizers','radish salad',6);
menu.addDishToCourse('appetizers','soup of the day',5);
menu.addDishToCourse('appetizers','chicken liver pate',9);
menu.addDishToCourse('mains','braised ox cheek with roasted vegtables',15);
menu.addDishToCourse('mains','turbot and apple',25);
menu.addDishToCourse('mains','ribeye steak and chips',20);
menu.addDishToCourse('desserts','eton mess',10);
menu.addDishToCourse('desserts','cheesecake',8);
menu.addDishToCourse('desserts','profiteroles',9);
meal = menu.generateRandomMeal() //assignsthe randomly generated meal
console.log(meal)
Appreciate your time!