Can someone please help me understand my error?

I am doing the “Meal Maker” challenge in the Javascript course. I am close to completing it, plus I watched the associated video. I cannot understand why there is an error on line 37. The error says the “push” property can’t be identified by I can’t understand why. Thanks!


const menu = {

    _courses: {

        appetizers: [],

        mains: [],

        desserts: [],

    },

    get appetizers() {

        return this._courses.appetizers;

    },

    get mains() {

        return this._courses.mains;

    },

    get deserts() {

        return this._courses.deserts;

    },

    set appetizers(appetizers) {

        return this._courses.appetizers = appetizers;

    },

    set mains(mains) {

        return this._courses.mains = mains;

    },

    set deserts(deserts) {

        return this._courses.deserts = deserts;

    },

    get courses() {

        return {

            appetizers: this.appetizers,

            mains: this.mains,

            deserts: this.deserts

        };

    },

    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 = Mathl.floor(Math.random(dishes.length))

        return dishes[randomIndex];

    },

    generateRandomMeal() {

        const appetizer = this.getRandomDishFromCourse('appetizers');

        const mains = this.getRandomDishFromCourse('mains');

        const desert = this.getRandomDishFromCourse('deserts');

        const totalPrice = appetizer.price + main.price + deserts.price;

        return `Your meal is ${appetizer.name}, ${main.name}, and ${desert.name} The price is ${totalPrice}.`;

    }

};

menu.addDishToCourse('mains','hamburger',10);

menu.addDishToCourse('mains','sandwich',10);

menu.addDishToCourse('mains','steak',10);

menu.addDishToCourse('appetizers','salad',8);

menu.addDishToCourse('appetizers','chips',8);

menu.addDishToCourse('appetizers','soup',8);

menu.addDishToCourse('deserts','cookie',4);

menu.addDishToCourse('deserts','cake',4);

menu.addDishToCourse('deserts','ice cream',4);

const meal = menu.generateRandomMeal();

console.log(meal);
1 Like

Hi there, welcome to the forums.

To start with, I think you should check your spelling of the word dessert. :slight_smile:

Thank you! I have made the fix. My next problem is that it is not “randomly” picking from the list of meals.

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) {

        return this._courses.appetizers = appetizers;

    },

    set mains(mains) {

        return this._courses.mains = mains;

    },

    set desserts(desserts) {

        return this._courses.desserts = desserts;

    },

    get courses() {

        return {

            appetizers: this.appetizers,

            mains: this.mains,

            desserts: 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 appetizers = this.getRandomDishFromCourse('appetizers');

        const mains = this.getRandomDishFromCourse('mains');

        const desserts = this.getRandomDishFromCourse('desserts');

        const totalPrice = appetizers.price + mains.price + desserts.price;

        return `Your meal is ${appetizers.name}, ${mains.name}, and ${desserts.name} The price is ${totalPrice}.`;

    }

};

menu.addDishToCourse('mains','hamburger',11);

menu.addDishToCourse('mains','sandwich',10);

menu.addDishToCourse('mains','steak',9);

menu.addDishToCourse('appetizers','salad',8);

menu.addDishToCourse('appetizers','chips',7);

menu.addDishToCourse('appetizers','soup',6);

menu.addDishToCourse('desserts','cookie',3);

menu.addDishToCourse('desserts','cake',2);

menu.addDishToCourse('desserts','ice cream',1);

const meal = menu.generateRandomMeal();

console.log(meal);
1 Like

Take a look at your use of Math.random(). (MDN)

It doesn’t take any parameters… so you’re constantly getting a float between 0 and 1, then rounding it down - which is why your “random” meal is always the first item in each course array. :slight_smile:

Should be easy to fix, though. :slight_smile: