Meal Maker Project- Wrong output

Hello Every,

I’m completing the Meal Maker Project. I can’t seem to understand why I continue to get “Meal or price was not set correctly!”. Can anyone help me understand what’s wrong with my code? I’m supposed to be getting Today’s Special is ${this._meal} for $${this._price}`.

Thank you

const 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 === true) {
return Today's Special is ${this._meal} for $${this._price};
} else {
return “Meal or price was not set correctly!”;
}
},
};

menu.meal = ‘pizza’;
menu.price = 50;
//console.log(menu)
console.log(menu.todaysSpecial);

To preserve code formatting in forum posts, see: [How to] Format code in posts

// You wrote:
if (this._meal && this._price === true) {

// It should be:
if (this._meal && this._price) {

There is a difference between something being truthy (Truthy - MDN Web Docs Glossary: Definitions of Web-related terms | MDN) and something being equal to the boolean value true.
A price of 50 is truthy, but 50 is not equal to the boolean value true.

Consider the following example:

let myArray = ["abc", "", 5, 0, true, false];

for (const element of myArray) {
    console.log(`Element: ${element}`);
    
    if (element) {
        console.log("This element is truthy.");
    }
    
    if (element == true) {
        console.log("This element is the boolean true.");
    }
    
    console.log("\n");
}

Have a look at the output and think about why each console.log statement is being printed or not printed.

// "abc" is truthy but not equal to true.
"Element: abc"
"This element is truthy."

// The empty string "" is neither truthy nor equal to true.
"Element: " 

// 5 is truthy but not equal to true.
"Element: 5"
"This element is truthy."

// 0 is neither truthy nor equal to true.
"Element: 0"

// The boolean true is both truthy and equal to true.
"Element: true"
"This element is truthy."
"This element is the boolean true."

// The boolean false is neither truthy nor equal to true.
"Element: false"
3 Likes

Thank you!!! So much. It worked!

1 Like