Javascript Objects Meal Maker Project - Setters and Getters

Hi everyone,

This is a question about the JS objects project: https://www.codecademy.com/journeys/full-stack-engineer/paths/fscj-22-building-interactive-websites/tracks/fscp-22-javascript-syntax-part-ii-c8ddbace-1463-4797-ae12-503c7b0f9552/modules/wdcp-22-learn-javascript-syntax-objects-42047fd1-bfb5-4b90-96a5-431acbee8013/projects/meal-maker

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;
console.log(menu);
console.log(menu.todaysSpecial);

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?

Thanks

Wow…

I literally spotted the issue as I reread this post…

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