Magic 8 ball project question - Why $userName not being recognized?

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-conditionals/projects/magic-eight-ball-1

So I am on step 2 in this project, and this is what I have so far:

let userName = 'Alex';

userName ? console.log(`Hello, $userName`) : console.log('Hello!');

The problem is that when I hit save, what shows up is: Hello, $userName

Instead of: Hello, Alex

Is there something I’m doing wrong?

Hi @alexanderflood876614
coming from JQuery or php?

This is not Javascript.

I’m not sure as I’m really new to this, sorry. I was following this video and at 1:35 I followed exactly what was entered: Learn JavaScript: Magic Eight Ball - YouTube

Ok, I was just wondering why you prefix your variable with a $. That’s typical for JQuery for example. But not for Javascript. Your variable is named userName not $userName.
Maybe that’s also caused by wrong formatting. Did you want to write a string literal like

console.log(`${userName}`)

Then you have a syntax error which we can’t see due to the formatting.

Please see this link:
How to format code in a post

Aah :grinning:
You forgot the braces. Variables in a string literal (strings and variables/code inside backticks) are highlighted with ${}:

console.log(`Hello, ${userName}`);
2 Likes

Thank you! I appreciate all of your help.

1 Like