Ternary Conditional - Username - Help!


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

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

TIA
Rachael

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


#2

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.


#3

Sorted. Thanks

Still getting used to all the different JavaScript syntax


#4

you’re welcome

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


#5

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