Why isn't is counting correctly?

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!
const menu = {
    _courses: {
      appetizers: [],
      mains: [],
      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 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 ${appetizer.name}, ${main.name} and ${dessert.name} and the total price is ${totalPrice}`;
    },
  

    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;
    },
  };
  
  menu.addDishToCourse('appetizers', 'salad', '15');
  menu.addDishToCourse('mains', 'wings', '38');
  menu.addDishToCourse('desserts', 'filet', '8');

  
  
  const meal = menu.generateRandomMeal();
  console.log(meal);

because your prices are strings:

  menu.addDishToCourse('appetizers', 'salad', '15');
  menu.addDishToCourse('mains', 'wings', '38');
  menu.addDishToCourse('desserts', 'filet', '8');

last argument of each method call. Because you have strings (and not numbers), the strings are added together (concatenated)

perfect thanks. haven’t seen it anymore :slight_smile: