Meal Maker help

Hi everyone, could anyone please help me find out the issue

Code:`const menu = {
_menu: ‘’,
_price: 0,

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

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

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

};

menu.meal = ‘Pizza’;
menu.price = 8;

console.log(menu.todaysSpecial);`

Link: https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker

Hi, please check out this guide about asking good questions.

Major issues in short

  • the correct category is Javascript
  • describe the issue you’re facing – what do you expect and what do you get instead
  • format your code

You will see an error in the console. Posting it here would help others and yourself tracing the error.
In your case the issue is referencing undefined variables with this keyword. Not everything you’re trying to return is defined as an object property.

2 Likes

yes ok

console: /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

Code:
`const menu = {
_menu: ‘’,
_price: 0,

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

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

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

};

menu.meal = ‘Pizza’;
menu.price = 8;

console.log(menu.todaysSpecial);`

I really recommend you to read the guide. The more effort you put in your post, the more likely it is that someone else puts some effort in reading it.

Pay some attention to these issues:

I did already point out a problem in your code:

Check which object properties you have defined and if they match with the properties you reference (they don’t).

Hi there! I’ve noticed some mistakes:

  1. You used another symbol than the quote. For example, your choice is - ‘’. Should use - ‘’. (looks almost similar) This is the button next to the colon, to the right of it.

  2. In this snippet of code you omitted the backticks on each side of executed code.

*your variation.

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

*should be

get todaysSpecial() {
if (this._meal && this._price) {
return `Today's Meal is ${this._meal} for $${this._price}!`
} else {
return `Meal or price not set correctly!`
}
}
  1. That issue about you mentioned :

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

SyntaxError: Unexpected token ‘,’

It shows that you miss 1 closed curly brace after your first fragment of setter :

set meal(mealToCheck) {
if (typeof mealToCheck === 'string') {
return this._meal = mealToCheck;
}
},
  1. And the last moment, inside of the second setter you need to write underscore (_) before the returned property.
    Your variation is “return this.price = priceToCheck;”
    Should be “return this._price = priceToCheck;”

Here’s the full correct code:

const menu = {
_menu: '',
_price: 0,

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

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

get todaysSpecial() {
if (this._meal && this._price) {
return `Today's Meal is ${this._meal} for $${this._price}!`
} else {
return `Meal or price not set correctly!`
}
}

};

menu.meal = 'Pizza';
menu.price = 8;

console.log(menu.todaysSpecial);

.