Meal Maker Project Question -- My set function. Why isnt this working?!

Im currently doing the “Meal Maker” project in the Javascript course. Link here.

I’m using the code in the post here. What I don’t understand is why after I’m calling my set function that console.log(menu.meal) isnt returning hamburger.

const menu = { _meal: "hotdog", _price: 0, set newMeal(mealToCheck) { if (typeof mealToCheck === 'string') { mealToCheck = this._meal; } else { console.log("not a string!"); } }, }; menu.newMeal = "hamburger"; console.log(menu._meal);

I figured it out. I wasnt returning the value of this._meal. updated code here. I also updated the naming conventions to better follow along the point of using the underscore naming convention.

1 Like

[codebyte language=javascript]

const menu = { _meal: "hotdog", _price: 0, set meal(mealToCheck) { if (typeof mealToCheck === 'string') { return this._meal = mealToCheck ; } else { console.log("not a string!"); } }, }; menu.meal = 'hamburger'; console.log(menu._meal);

Good Job! It is not needed the return but its a great job and explicit!