Why is `favorite_Phase === 'Love That!'` required?

Hi I have been stuck on this for days , pulling my hair out . Can someone tell me what is wrong with this I have read every post here but still cant get past this , this is what i got let isLocked = false;

isLocked ? console.log(‘You will need a key to open the door.’) : console.log(‘You will not need a key to open the door.’);

let isCorrect = true;

isCorrect ? console.log(‘Correct!’) : console.log(‘Incorrect!’);

let favoritePhrase = ‘Love That!’;

favoritePhrase ? console.log(‘I love that!’) : console.log(“I don’t love that!”);

isCorrect works with ? without a problem because it is a boolean variable (meaning a variable that stores true or false).
favoritePhrase does not work with ? the same way bacause favoritePhrase is a string
(I think that non-empty strings always give you true if you try to use them instead of a boolean. They are truthy.)
So you need to have something that evaluates to true or false to the left of the ?
like: favoritePhrase === 'Love That!'

thanks for reply but still cant get it to work cheers i give up :woozy_face:

I kind of understand this, but I’m still unsure of it a little bit. I had trouble with this exercise too. Since the operator === means is equal to, is the reason why we have to put p === ‘Love That!’ before the ternary operator, because the value is not assigned to the variable P?

The condition being tested is whether or not the variable p is assigned to the string literal 'Love That!'. If it is, the value immediately following the ternary operator is returned. If it isn’t, the value following the : is returned instead. I wrote that answer some time ago, and it’s not really a good example of using a ternary expression. The following would be better:

let p = "Love That!";

console.log(p == "Love That!" ? "I love that!" : "I don't love that!");

// if we wanted to assign a value using the ternary expression we could do this

p = "meh" // change the value p is assigned to

const response = p === 'Love That!' ? "I love that!" : "I don't love that!";

// then we can print response or do whatever else with it



I love that!
I don’t love that!