Meal Maker - Project, wrong total price

hello,
i cant find the problem, the total price is wrong…

const meniu = {

    _courses: {

        appetizers: [],

        mains: [],

        desserts: []

        },

    get appetizers () {

        return this._courses.appetizers;

    },

    set appetizers (appetizers) {

        return this._courses.appetizers;

    },

    get mains () {

        return this._courses.mains;

    },

    set mains (mains) {

        return this._courses.mains;

    },

    get desserts () {

        return this._courses.desserts;

    },

    set desserts (desserts) {

        return this._courses.desserts;

    },

    get_courses () {

        return {

            appetizers: this._courses.appetizers,

            mains: this._courses.mains,

            desserts: this._courses.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 + appetizers.price;

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

       

    }

};

// appetizers course

meniu.addDishToCourse('appetizers', 'sticky', 1);

meniu.addDishToCourse('appetizers', 'crab', 2);

meniu.addDishToCourse('appetizers', 'hogs', 3)

//mains course

meniu.addDishToCourse('mains', 'hotdog', 4);

meniu.addDishToCourse('mains', 'kebab', 5);

meniu.addDishToCourse('mains', 'salam', 6)

//mains desserts

meniu.addDishToCourse('desserts', 'rafaello', 7);

meniu.addDishToCourse('desserts', 'milka', 8);

meniu.addDishToCourse('desserts', 'snikers', 9)

const meal= meniu.generateRandomMeal();

console.log(meal);

console.log(meniu._courses.appetizers)

console.log(meniu._courses.mains)

console.log(meniu._courses.desserts)

What exactly do you expect it to output? What’s the goal total price?

On the total price you are adding the

appetizers + mains + appetizers (Again).

Instead you should add the desserts. So the price should be calculated from the sum of

appetizers + mains + desserts

1 Like