Javascript Objects Meal Maker Project - Setters and Getters

Hi everyone,

This is a question about the JS objects project:

The aim is to create an object with getters and setters.

Here is my code:

let menu = {
  _meal: '',
  _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 Special is ${this._meal} for \$${this.price}!`;
    } else {
      return 'Meal or price was not set correctly!';

menu.meal = 'sausage';
menu.price = 6;

Here is the output:

  _meal: 'sausage',
  _price: 6,
  meal: [Setter],
  price: [Setter],
  todaysSpecial: [Getter]
Meal or price was not set correctly!

This issue I’m having is that although _price appears to be updating from the setter, the getter is returning the else statement. If I force it to return true, _price is undefined.

Can anyone point me to the error please?



I literally spotted the issue as I reread this post…

I wasn’t referencing _price at all! Silly me.