Meal Maker project: Advanced Objects

#AdvancedObjects
https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker

I am currently stuck at step 8 where you have to create a method .addDishToCourse. When i tried it myself i didn’t get it right so i decided to take a look at the hint. Then i copied the hint and got this error when calling the method like so: menu.addDishToCourse(‘appetizers’, ‘Bruscheti’, ‘10.5$’);. The error said: this._courses[courseName].push is not a function. I then went ahead and looked at the video guide on youtube and he had done the same thing as me but didn’t get this error, could anyone please tell my why am I getting this error please ?

Difficult to say without seeing the code. Please copy paste the code to the forum

The link you provided will check for logged in/authenticated user, so if I click that link, I will see my own code. The link is still useful for me, but I am still missing a vital piece (the code itself)

1 Like
const menu = {

  _courses: {

    appetizers: [1],

    mains: [],

    desserts: [],

    get appetizers() {

      return 2;

    },

    set appetizers(appetizers) {

    },

    get mains() {

    },

    set mains(mains) {

    },

    get desserts() {

    },

    set desserts(desserts) {

    }

  },

  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 randomIndes = Math.floor(Math.random()*(dishes.length - 1));

    return dishes[randomIndex];

  },

  generateRandomMeal() {

    const appetizer = this.getRandomDishFromCourse(appetizers);

    const main = this.getRandomDishFromCourse(mains);

    const dessert = this.getRandomDishFromCourse(desserts);

  }

};

menu.addDishToCourse('appetizers', 'Bruscheti', '10.5$');

if we add a .log() for debug purposes:

    console.log(this._courses[courseName]);
    this._courses[courseName].push(dish);

we can see that this_coures[courseName] gives a Number. .push() is an array method

the Number comes from appetizers getter. The getters now have the same name as the property, which is very risky.

1 Like

Oh, i can’t believe i’m this stupid :sweat_smile:, thank you for poiniting this out and helping

To use .log() to inspect the state of your code/program or even a bebugger (like this one) can be very can be really useful :slight_smile: