You're missing backticks around the string you're trying to interpolate
Wrap this string: URL('....${number})' in backticks, backtick: `
You're missing backticks around the string you're trying to interpolate
Wrap this string: URL('....${number})' in backticks, backtick: `
I solved this problem by concatinating URL with searchValue and then adding the remaining part of url, here's a example:
let searchValue="lahore";
let url='https://api.RandomWebsite.org/data/2.5/weather?q='+ searchValue + '&appid=API_KEY';
I have the following function.
function hello() {
var name = 'John';
var age = 32;
console.log('My name is ${name}, and I am ${age} years old');
}
After calling the function it does not interpolate the string placeholders. Therefore the output is:
My name is ${name}, and I am ${age} years old
I have tried this in node and in chrome. I have tried in a file.js file then called it with node in the terminal.
My current version of node is v14.11.0
Am I crazy and missing something here?
Since ES6, you can use template literals:
const age = 3
console.log(`I'm ${age} years old!`)
P.S. Note the use of backticks: ``.
tl;dr
Use ECMAScript 2015's Template String Literals, if applicable.
Explanation
There is no direct way to do it, as per ECMAScript 5 specifications, but ECMAScript 6 has template strings, which were also known as quasi-literals during the drafting of the spec. Use them like this:
> var n = 42;
undefined
> `foo${n}bar`
'foo42bar'
You can use any valid JavaScript expression inside the {}. For example:
> `foo${{name: 'Google'}.name}bar`
'fooGooglebar'
> `foo${1 + 3}bar`
'foo4bar'
The other important thing is, you don't have to worry about multi-line strings anymore. You can write them simply as
> `foo
... bar`
'foo\n bar'
Note: I used io.js v2.4.0 to evaluate all the template strings shown above. You can also use the latest Chrome to test the above shown examples.
Note: ES6 Specifications are now finalized, but have yet to be implemented by all major browsers.
According to the Mozilla Developer Network pages, this will be implemented for basic support starting in the following versions: Firefox 34, Chrome 41, Internet Explorer 12. If you're an Opera, Safari, or Internet Explorer user and are curious about this now, this test bed can be used to play around until everyone gets support for this.
As per the documentation on Template Literals, replace your code with this:
let prompt = this.question.prompt.replace(`{{${this.answerCode}}}`,this.LookupAnswer(this.answerCode));
Replace " with backticks ` and enclose the variable with ${ }
Instead try with string template literals:
`${this.answerCode}`