Stuck with JS (Meal Maker Project)

I’m stuck with this little project. I have followed the video along and still getting error I cannot figure out :sweat_smile:

"TypeError: Cannot read property ‘push’ of undefined
at Object.addDishToCourse "

any help much appreciated, cheers !

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 = appetizers;
    set mains(mains) {
        this._courses.mains = mains;
    set desserts(desserts) {
        this._courses.desserts = desserts;
    get courses() {
        return {
            appetizers: this.appetizers,
            mains: this.mains,
            dessers: this.desserts,
    addDishToCourse(courseName, dishName, dishPrice) {
        const dish = {
            name: dishName,
            price: dishPrice,
        return 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 ${}, ${}, and ${}, and the total price is ${totalPrice}`;

menu.addDishToCourse('appertizers', 'salad', 4.00);
menu.addDishToCourse('appertizers', 'wings', 5.00);
menu.addDishToCourse('appertizers', 'fries', 4.50);

menu.addDishToCourse('main', 'steak', 9.50);
menu.addDishToCourse('main', 'chicken', 8.50);
menu.addDishToCourse('main', 'soup', 5.50);

menu.addDishToCourse('dessert', 'ice cream', 2.50);
menu.addDishToCourse('dessert', 'cake', 5.00);
menu.addDishToCourse('dessert', 'coffee', 2.50);

const meal = menu.generateRandomMeal();

Hi @mikesparrow
Welcome to the forum!

This is what you want to push to and what can’t be found:

So have a look at your _courses object. What should this._courses[courseName] be in dot notation?
Add a console.log(courseName) to your addDishToCourse method and see what you get. Does that match the course names in your _courses object?

1 Like


I would make sure that your spellings of your courseNames are correct when you’re adding them to the menu. I noticed quite a few don’t line up. And there’s also one more you’ll need to fix when you find where those misspellings are.

I went through and fixed them all on my end and I was able to run the code.


Each one of these adds do not line up with your courseNames. After that you’ll find another error, but you should be able to figure that out :blush:

1 Like

Hi @mirja_t and @keegankwirant8521787!

Thank you so much for taking time looking over my code, both of you were really helpful! I made some really careless mistakes…

I should triple check what I’m typing :sweat_smile:


1 Like

you can check this link.