Meal Maker

hello i got problems with Meal Maker project.
when is runningi got an error:
Uncaught ReferenceError: courseName is not defined
at Object.getRandomDishFromCourse ((index):57)
at Object.generateRandomMeal ((index):63)
can someone help me.

this is the code:

this is the code
let menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  },
  
  get appetizers() {
    return this.appetizers;
  },
  
  set appetizers(appetizerIn) {
    this.appetizers.push(appetizerIn);
  },
  
   get mains() {
    return this.mains;
  },
  
  set mains(mainIn) {
    this.appetizers.push(mainIn);
  },
  
   get desserts() {
    return this.desserts;
  },
  
  set desserts(dessertIn) {
    this.appetizers.push(dessertIn);
  },
  
  get courses() {
    return {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts
    }
  },
  
  addDishToCourses(courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
    };
    this._courses[courseName].push(dish);
  },
  
  getRandomDishFromCourse(CourseName) {
    let dishes = menu._courses[courseName];
    let 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 `Ai mincet de ${totalPrice} si ai mincat ${appetizer.name}, ${main.name}, ${dessert.name}.`;
    
  }
};

menu. addDishToCourses('appetizers', 'buter', 2);
menu. addDishToCourses('appetizers', 'peceni', 1.20);
menu. addDishToCourses('appetizers', 'blinciki', 2.25);

menu. addDishToCourses('mains', 'zeama', 3.20);
menu. addDishToCourses('mains', 'tocana', 4.60);
menu. addDishToCourses('mains', 'piure cu kotlete', 3 );

menu. addDishToCourses('desserts', 'napoleon', 3.20);
menu. addDishToCourses('desserts', 'medovic', 2.75);
menu. addDishToCourses('desserts', 'papanasi', 5.50);

let meal = menu.generateRandomMeal();
console.log(meal);
2 Likes

here:

let dishes = menu._courses[courseName];

courseName is indeed undefined.

variable names are case sensitive, where is this variable defined?

1 Like

let dishes was already declared once at getRandomDishFromCourse(CourseName).
Tnx anyway.

1 Like

i found the problem i wrote courseName instead of CourseName.
thx for hellping, i was more accurately looking after waht u wrote.

1 Like