JavaScript Magic 8 Ball

const userName = “Melissa”;

userName === “Melissa” ? console.log(“Hello ${userName}”)
: console.log(“Hello!”);

const userQuestion = “How many computer science classes will I take?”;

console.log(“The user asked: ${userQuestion}”);

This is my code, but when it prints to the console, it reads
Hello {userName} The user asked: {userQuestion}

Why is my string interpolation not working?

Thanks, Melissa

Nevermind,

I figured it out… I need to use back ticks :slight_smile:

You can only use $variables in combination with backtick concatenation.

userName === “Melissa” ? console.log(`Hello ${userName}`) : console.log(“Hello!”);

const userQuestion = “How many computer science classes will I take?”;

console.log(`The user asked: ${userQuestion}`);

If you want to use strings, you can only achieve this by splitting up like so:

console.log("Hello " + userName)

Yes, I was trying to do it the quickhand way, and I used apostrophes instead of back ticks… I didn’t notice for like an hour what the issue was.