FAQ: Variables - String Interpolation

var myName= ‘Anna’;
var myCity = ‘Stroud’;
console.log(My name is ${myName}. My city is ${myCity}.);

I used backtick and dollar sign. Why am i getting this wrong?
The output is correct but it the system will not accept the answer as correct so i cannot progress further.

I typed in my name and my favorite city and it generated an error. I was confused so I clicked on view solution. I found out that there is a random name and that you can’t type any name except that! WHAT IS THIS?!!?

Able to replicate this issue so it must be an SCT problem.

Did you interpolate myName and myCity using back ticks and ${} ?

@catower, can you follow up and confirm, please?

For the answer to be correct, ensure that the text matches this format exactly.
My name is ${myName}. My favorite city is ${myCity}
The user above was missing the word favorite from the sentence.

The solution has an example name and city (in fact this is the name of the developer who wrote this and her favorite city), but the code will pass irregardless of what your own name or city preference is, as long as the string matches and the variables are named correctly. Cheers!

2 Likes

D’oh! So obvious. Thanks, again.

1 Like

Hello, I was just wondering if there was any difference between these two instructions in JavaScript? I found that there’s an execution difference between concatenation and string interpolation, but I couldn’t find anything about using the %s format specifier versus string interpolation. Is one more optimal/faster than the other?

let a = "Name"
console.log("Hello there, %s", a)
console.log(`Hello there, ${a}`)