Refactor, or edit, the first if...else block to use a ternary operator

Hi guys, I’m stucked here:
Codecademy version i have to refactor or edit:

let isLocked = false;

if (isLocked) {
  console.log('You will need a key to open the door.');
} else {
  console.log('You will not need a key to open the door.');
}

My code:

let isLocked = false;

isLocked ? 'You will need a key to open the door.':'You will not need a key to open the door.'; 

I’m really stuck at this point and I ve been looking on the internet and can’t find an answer, thanks for the help in advance!

It appears that you’re just missing the console.log. The original snippet logs a string to the console. Your code doesn’t log anything to the console.

Yeah, actually that was wron, the final and working code is:

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

thanks a lot for the help

1 Like

Sure. You can tidy that code up a little by using only one console.log.

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