Question:
Why does the sentence of my code include the ${} symbols with it?
Repl link:
code snippet
const introducer = (name, shirt) => {
const person = {
name: name,
shirt: shirt
}
const intro ='Hi, my name is ${person.name} and the color of my shirt is ${person.shirt}'
return intro
}
console.log(introducer('James', 'black'))
console.log(introducer('Leonardo', 'shirt'))
This is a javascript string substitution syhstem:
Hi, my name is James and the color of my shirt is black
Hi, my name is Leonardo and the color of my shirt is shirt
1 Like
Change the single quotes to backtics ` if you want to use string formatting.
3 Likes
Change this:
const intro ='Hi, my name is ${person.name} and the color of my shirt is ${person.shirt}'
to this:
const intro =`Hi, my name is ${person.name} and the color of my shirt is ${person.shirt}`