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 trial

JavaScript JavaScript Basics Working with Strings Write a Template Literal

KJ Lee
KJ Lee
1,059 Points

Does anyone know what the template literal would be here?

app.js
const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;

const drink = `${flavor} ' ' ${type} ':'' $' ${price}`;

2 Answers

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

Template literals are also called back ticks. On the keyboard they are above Tab If you want to get 'Blueberry Smothie: 4.99' the last line should go like this

const drink = ${flavor}${type} :${price};

For some reason they don't show here on this platform

Fred Baker
Fred Baker
4,061 Points

This isn't quite right. The correct answer is:

const drink = `${flavor} ${type}: $${price}`;

Make sure to add the template literal (`) to enclose the string, and each variables goes inside the interpolation ${}. Finally, you have to make sure the : is DIRECTLY behind the type variable and the $ is DIRECTLY before the price, with no spaces between the symbol and function (there is a space between the : and $).

KJ Lee
KJ Lee
1,059 Points

Thank you man!

Fred Baker
Fred Baker
4,061 Points

Dmitry, it didn't for me at first either. when code is indicated, you have to use 3 backticks before and after the line so it captures everything inside as code.

KJ, sure thing!