Hello I have been struggling with this for the last couple of days.
I found many items on this subject of object error line 37 but also found that there could be many reason it to be caused, yet i could not make what it is that I am doing wrong.
After wondering if I might not be smart enough to learn coding, I actually experienced some clues that its not just me in this excercise; a vamp up excercise originally not designed to teach getters and setters.
In this excercise I really needed all the get help possibilities.
I think i kind of get the concept of getters (gets the keys of an object) and setters (sets or alters the keys).
But i really would like to see this script work, what is it what I am not seeing?
And I was trying to use the debugger in VS but also that I did not get to work.
hope to get some feedback.
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(appetizer) {
this._courses.appetizers = appetizer;
},
set mains(main) {
this._courses.mains = main;
},
set desserts(dessert) {
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].push(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 `Your meal is ${appetizer.name}, ${meal.name} and ${dessert.name} and the total price is ${totalPrice} `;
}
};
menu.addDishToCourse('appetizers', 'shrimp cocktail', 5);
menu.addDishToCourse('appetizers', 'fish soup', 6);
menu.addDishToCourse('appetizers', '6 oysters', 15);
menu.addDishToCourse('appetizers', 'sumac unions & garlic bread', 7,50);
menu.addDishToCourse('meals', 'beef cheecks', 20);
menu.addDishToCourse('meals', 'korean ramen 1', 15);
menu.addDishToCourse('meals', 'sichuan ramen', 12);
menu.addDishToCourse('meals', 'japanese ramen', 13.50);
menu.addDishToCourse('desserts', 'banana split', 6);
menu.addDishToCourse('desserts', 'cheese platter', 12);
menu.addDishToCourse('desserts', 'heavenly mud', 8);
menu.addDishToCourse('desserts', 'coffee deluxe', 6);
menu.addDishToCourse('desserts', 'fresh fruit', 7);
menu.addDishToCourse('desserts', 'chocolate mousse', 6);
const meal = menu.generateRandomMeal();
console.log(meal);
You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!