https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker
I’m new to Codecademy. This is my first post so please be patient with me.
First of, I haven’t had issues up until I got to Objects and especially this exercise ‘Meal Maker’. I hate to say this but I completely don’t understand how to put this together. I tried to follow the steps again and again but my code is not working. I watched the video and the guy is going too fast and didn’t help.
Here is what I need help with:
- Pleas tell me why my code is not working. I posted the link to it. Please tell me if there is a better way to post codes in the future.
- Why do we need setters and getters here
- anything that explains this code will help.
Thanks in advance
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
},
get appetizers() {
return this._courses.appetizers;
},
set appetizers(appetizerIn) {
this._courses.appetizers;
},
get mains() {
return this._courses.mains;
},
set mains(mainIn) {
this._courses.mains;
},
get desserts() {
return this._courses.desserts;
},
set desserts(dessertsIn) {
this._courses.desserts;
},
get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: courseName,
price: dishPrice
};
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
},
generateRandomMeal: function() {
const appetizer= this.getRandomDishFromCourse('appetizers');
const mains = this.getRandomDishFromCourse('mains');
const desserts = this.getRandomDishFromCourse('desserts');
const totalPrice = appetizer.price + mains.price + desserts.price;
return `Your meal is ${appetizer.name}, ${mains.name}, ${desserts.name}, the price is ${totalPrice}.`
}
};
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);
let meal = menu.generateRandomMeal();
console.log(meal)