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 trialAlonzo Delk
6,991 Pointshow do I add flavor to this deal of code?
const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;
const drink = flavor + ' ' + type + ': ' + '$' + price;
const flavor = "Blueberry Smoothie"
const price = 4.99
const sentence = `{I'm excited about trying this blueberry smoothie flavor, can't wait!}`;
2 Answers
Peter Vann
36,427 PointsHi Alonzo!
First, the tests don't do well with repeated code (won't pass), so replace the existing drink string.
Second, template literals (the entire string) must be surrounded by backticks (the character above the tab key and to the left of the 1/! key - the same key's uppercase value is tilda: ~
You reference the variables by encasing them in ${ }
Example: ${flavor}
So it looks weird but to have a variable with a dollar sign in front, you need to use $${ }, which is not exactly intuitive.
So you end up with: $${price}
Anyway this passes:
const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;
const drink = `${flavor} ${type}: $${price}`;
More info:
https://css-tricks.com/template-literals/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
I hope that helps.
Stay safe and happy coding!
Alonzo Delk
6,991 Pointsconst flavor = "Blueberry"; const type = "Smoothie"; const price = 4.99;
const drink = (${blueberry}) (${smoothie}): ($${4.99})
;
what am I doing wrong because it's saying that the value of flavor is not entered into the string?