Why isn't string interpolation working? (Check for backticks)

console.log("My name is {myName}.` My favorite city is {myCity}.`);

hi my code as above but its not working. i use the back tick. pls help

Hello people,
same here. I don´t get it: it prints out just fine but still it doesn´t let me move ahead to the next page.

I wrote:

console.log(My Name is ${myName}. My favorite city is ${myCity}.)

backticks are there and as I said it printed out the way it should but still says: X

thanks for help, I´m stuck for today…

oh and I copied the backticks in here but they don´t show in the paste. hm``````

Perhaps change Name to name?

1 Like

thank you very much! made my day.

1 Like

Thanks I forgot the backticks

let myName = “Kaden”;
let myCity = “Jacksonville”;
console.log(My name is ${myName}. My favorite city is ${myCity}.);

i think there is some sort of bug in it, i actually just put the Code Academy solution, and it doesn’t work !
any tips on how to pass this step ?
the codeacademy code that doesn"t work : 7
let myName = ‘Natalia’;

let myCity = ‘Mexico City’;

console.log(My name is ${myName}. My favorite city is ${myCity}.) ;

OMG you know what fixed this??? Rebooting my laptop. I thin it got stuck.

Sobre esse erro, é que você deve usar os back-sticks…
basta imprimir o resultado da seguinte maneira:
console.log(My name is ${myName}.My favorite city is ${myCity})

Is there a reason for the $ to be attached to the braces containing the assigned value of the variable? Or is that just how it is in JScript?

It is common to JS, only, as far as I know. Some languages use the $ sign to denote a variable. In template literals, they are the variable within the template.

console.log(`I want to eat a ${fruit}.`)
//                           --------
//                                \
//                        variable placeholder

Whatever value fruit refers to will be cast to its string representation and inserted in the text in place of the variable interpolation placeholder.

We should note that not just variables can be written into the placeholder. Whole expressions may be written there since all expressions yield a value.

1 Like
let myName = 'Himanish Das'; let myCity = 'Mexico City'; console.log(`My name is ${myName}.`); console.log(`My favorite city is ${myCity}.`);

I don’t know why it is not working, it just keeps showing on on this error at the bottom of the code,(Did you interpolate myName and myCity using back ticks and ${} ?)

It prints the output just fine, but still doesn’t let me move onto the next exercise :thinking:

Got the answer. I was printing in different lines instead of same single line.