Can't get ${} to work

Hello,

I’m new to using the ${}.

I’m currently watching JavaScript tutorial and am on Input and Output.
Im writing exaclty as Zsolt in the console on Google but it still wont work.

const ticker = prompt('enter your crypto ticker');
const amount = +prompt('enter the amount you bought:');
console.log('you have just bought ${amount}${ticker}');

see how it’s always part of the string instead of being white text insided the curly brackets? Is there a special way to write the ${}?

Hey @Vendi, hope you are well.

The issue comes with the quote marks “”, there are 2 type of string messages, one its with the usual quotes “”, the new one is with curvy quotes ``.

Example:

let message = "IM TEXT MSG"
console.log("OLD way, variable: ", message);

console.log(`NEW WAY, Variable value is: ${message});

Carlos Z

1 Like

Hello @thecil ! Yes I am well thanks

Thanks alot, it worked!
I didn’t realise it was a new way to call a string with those quotation marks, is there a place where they publish these updates for JavaScript?

1 Like

You can read about the versions here:
https://www.w3schools.com/js/js_versions.asp

Also here is another article about this curvy quotes on JS and how to use it:
https://www.w3docs.com/snippets/javascript/when-to-use-double-or-single-quotes-in-javascript.html

Carlos Z

Hello,

I have a little bit the same problem, but when it starts in the beginning at the input of the name. The screen with the question ‘enter your name’, pops up. But in the next i dont get my name but ‘Greetings, ${name}’

this is what I have as code:

let name = prompt ('enter your name: ');
alert ('Greetings, ${name}')

This is my screen of the code

1 Like

I have found the problem :see_no_evil: I have to use back ticks

1 Like

Keep in mind that you need to use the curvy quotes if you want to display a variable into a message.

Incorrect:

'grettings, ${name}'

Correct:

`greetings, ${name}`

Carlos Z

1 Like