Meal Maker: Invalid shorthand property initializer

Still struggling with the Meal Maker project (https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-objects/projects/meal-maker) After I rewrote the code I got a new error:

_courses = {
^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer

What did I do wrong?

let menu = {
    _courses = {
        appetizers: [],
        mains: [],
        desserts: []
    },
    get courses () {
        return {
            appetizers: this._courses.appetizers,
            mains: this._courses.mains,
            desserts: this._courses.desserts
        }
    },
    addDishToCourse (courseName, dishName, dishPrice) {
        let dish = {
            name: dishName,
            price: dishPrice
        };
        this._courses[courseName].push(dish)
    },
    getRandomDishFromCourse (courseName) {
        const dishes = this._courses[courseName];
        const 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);
        let totalPrice = appetizer.price + main.price + dessert.price;
        return `You're having ${appetizer} for starters, ${main} as your main course and ${dessert} for dessert. The total price is ${totalPrice}`;
    }
}

menu.addDishToCourse('appetizers', 'Brushetta', 5);
menu.addDishToCourse('mains', 'Pizza', 15);
menu.addDishToCourse('desserts', 'Tiramisu', 8);

let meal = menu.generateRandomMeal()

console.log(meal);
1 Like

Look real close at that and ask if it uses the correct syntax.

1 Like