Ternary Conditional - Username - Help!

let userName = ('');
userName ? console.log(`'Hello' + ${userName}`) || console.log('Hello');

Can someone tell me what i’ve done wrong here?


*Edit - Doesn’t seem to show the backfacing apostrophes, but they are there ``

ternary operator syntax:

condition ? expr1 : expr2 

from the documentation. You use the or operator (||), which isn’t correct

the nice thing about the ternary operator is only need a single .log() call.

Sorted. Thanks

Still getting used to all the different JavaScript syntax

you’re welcome

yep, that takes time. Keep practicing, it will get better :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.