Meal Maker project

Hello everyone -

I’m at the end of my JavaScript course and working on the Meal Maker project. I can’t understand why I’m getting a syntax error. Can someone help me with this?

I made a copy of my text and the error message.

Thank you!

const menu = {
_meal: ‘’,
_price: 0,

set meal(mealToCheck) {
if (typeof mealToCheck === ‘string’) {
return this._meal = mealToCheck,
}
}, (this is line 7)

set price(priceToCheck) {
if (typeof priceToCheck === ‘number’) {
return this._price = priceToCheck,
}
},

get todaysSpecial() {
if (this._meal && this._price) {
return Today's Special is ${meal} for ${price}!
} else {
return ‘Meal or price was not set correctly!’
}
}
};

menu.meal = ‘Pizza’;
menu.price = 0;
console.log(menu.todaysSpecial);

/home/ccuser/workspace/learn-javascript-objects-meal-maker-update-2022/app.js:8
}
^

SyntaxError: Unexpected token ‘}’
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47

In case of syntax errors, the line isn’t always precise. Two lines above, you have an assignment in a statement that you end with a comma. That needs to be a semicolon (or nothing). That occurs in several places.
Additionally the return keyword is superfluous.

hello your issues are very simple byt confusing or common cases. i took your code and change all you quotes to real ones: ‘number’ and ‘string’. please fix those ones. alos, as it was said before, fix your return. assign and then return the value. Also, the returned value should be with “this” of such object.

please see the working code: ++++++++++++++++

const menu = {
_meal: ‘’,
_price: 2,

set meal(mealToCheck) {
if (typeof mealToCheck === ‘string’) {
this._meal = mealToCheck;
return this._meal;
}
},

set price(priceToCheck) {
if (typeof priceToCheck === ‘number’) {
this._price = priceToCheck;
return this._price;
}
},

get todaysSpecial() {
if (this._meal && this._price) {
return Today Special is ${this._meal} for ${this._price}
} else {
return "Meal or price was not set correctly! ";
}
}
};

menu.meal = ‘Pizza’;
menu.price=2.0;
console.log(menu.todaysSpecial);

That is due to the unformatted code. As you can probably see – the quotemarks of your code are odd as well because you didn’t format your code. So for both of you @flichi and @glenda9031 : If you mark your code and then press </>, you’ll get a readable code block which makes it easier for others to help you debug it.

1 Like

Thank you so much! I’ll do that project again!

1 Like

Thank you so much! I’ll do the project again!