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!

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

Are there anyone having trouble getting the template literal final string "Blueberry Smoothie: $4.99? I'm having trouble

const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;

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

1 Answer

Hi Julia,

Your code looks really good for the most part, but I see three things that will cause issues for you. One is that you've included the semi-colon (which in this case is meant to signal the end of a statement) inside your string (which would throw off the test code that's evaluating the challenge). Another thing is that you don't currently have a space between the ${flavor} and ${type} in your template string. And lastly, because you've already defined the variable drink as a const on line 5, you can't redeclare it on line 6 (that would result in an error). In fact, because the variable is a const variable, you can't even assign it a different value.

That said, I understand the value of not always deleting code when you're first learning (just in case you make a mistake, you can go back to the original version). If you don't want to change the code the challenge has given you directly, you can always comment out the part of the code that you will be altering using the following syntax: // <= This tells the interpreter to ignore everything on the same line that comes after that symbol.

Hope that helps. =)

LaShawna Thomas
LaShawna Thomas
1,845 Points

How do you add a space in between ${flavor} and ${type}???

Hi LaShawna,

You would just leave a space between the two templates, like so:

`${flavor} ${type}`

Have I misunderstood your question, or does ☝🏾that answer it for you?