Meal Maker Troubleshoot


Hey guys, my first post here. I’ve had a pretty smooth time so far doing the little code projects but this one has stumped me. I watched the instructional video a few dozen times and can’t seem to figure out where exactly I went wrong, so I figured I’d ask for a little help!
Here’s my code:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
  get appetizers() {
    return this._courses.appetizers
  get mains() {
    return this._courses.mains
  get desserts() {
    return this._courses.desserts
  set appetizers(appIn) {
    this._courses.appetizers = appIn;
  set mains(mainIn) {
    this._courses.mains = mainIn;
  set desserts(dessertIn) {
    this._courses.desserts = dessertIn;
  get courses() {
    return {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts
  addDishToCourse(courseName, dishName, dishPrice) {
    let dish = {
      name: dishName,
      price: dishPrice,
    return this._courses[courseName].push(dish);
  getRandomDishFromCourse(courseName) {
    let dishes = this._courses[courseName];
  	let randomIndex = Math.floor(Math.random * dishes.length);
    return dishes[randomIndex];
  generateRandomMeal() {
    let appetizer = this.getRandomDishFromCourse('appetizers');
    let main = this.getRandomDishFromCourse('mains');
    let dessert = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `Appetizer is ${}, main course is ${} and dessert is ${}. Total price is $${totalPrice}`;

menu.addDishToCourse('appetizers', 'Caesar Salad', 7.50);
menu.addDishToCourse('appetizers', 'Escargot', 10.00);
menu.addDishToCourse('appetizers', 'Calamari', 12.50);

menu.addDishToCourse('mains', 'Bison Burger', 17.50);
menu.addDishToCourse('mains', 'Grilled Salmon', 25.00);
menu.addDishToCourse('mains', 'Steak Frites', 30.00);

menu.addDishToCourse('desserts', 'NY Cheesecake', 12.50);
menu.addDishToCourse('desserts', 'Chocolate Ganache', 15.00);
menu.addDishToCourse('desserts', 'Tarte au Caramel', 5.00);

let meal = menu.generateRandomMeal();


And I’m receiving the error:

TypeError: Cannot read property ‘price’ of undefined
at Object.generateRandomMeal

Thanks in advance to anyone who helps me solve this! :pray:


Found it!!!

You arent calling .random function from Math correctly :wink: You are missing the ().

let randomIndex = Math.floor(Math.random() * dishes.length);


Took me 30 mins to spot the difference between my code and yours… :stuck_out_tongue:


Thank you so much!!! Ugh what a silly mistake, I’m so glad you found that. Now I can keep the rest of my hair :stuck_out_tongue_closed_eyes: