Javascript - ${ } issue

const target = Math.floor(Math.random() * 10);
let guess = Math.floor(Math.random() * 10);
while (guess !== target){
     guess = Math.floor(Math.random() * 10);
console.log('Target: ${target} Guess: ${guess}')

It shows random numbers and “Target: {target} Guess: {guess}”
Why doesn’t show - Target: 1
Guess: 1
That is if the numbers come the same.
Your help is appreciate it.


you need to use template literals syntax, which also means using backticks (`) instead of quotes to surround the string, then, the ${variable} will work

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Thank you so much. You been a great help.
Keep up the wonderful job.

Thanks again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.