Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOlga Pokrovskaya
1,885 Pointsconst flavor = "Blueberry"; const type = "Smoothie"; const price = 4.99; const drink = flavor + ' ' + type + ': ' + '$'
interpolation (${ }) - what is this bummer about? Here is what I write
nst drink = `${Blueberry} ${Smoothie}: $${4.99}
const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;
const drink = flavor + ' ' + type + ': ' + '$' + price;
const drink = `${Blueberry} ${Smoothie}: $${4.99}`
2 Answers
Nikos Papapetrou
6,305 PointsThe challenge is to use the template literal: the backticks(in the left-top corner of your keyboard) the dollar sign and inside the brackets the variable you have declare.
`${ variable_name }`
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Nicolette Grannum
Full Stack JavaScript Techdegree Graduate 15,152 PointsA template literal reads more naturally like a sentence. Instead of manually adding "(space)" each time you want a space in a string, you can simply type a space. The "${}"
is just so the program knows that it is a variable and not a string.
For this challenge, like Nikos said, you will want to include the variable name inside the curly braces, not the value. This way, you do not need to manually update the string every time the flavor, type, or cost changes. You used the variable names in the first 'drink' constant, and you would use them the same way below.
Also, as a general note, if you have 2 const
with the same name, it will give you an error even if the template literal is correct. Try using 'let' for the first and just 'drink=' for the second if you want to change the value. Or using a name other than 'drink' for your second line.