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

beConvert the set of concatenated strings assigned to the drink variable to a template literal. The final string should

Need help with this one.. Convert the set of concatenated strings assigned to the drink variable to a template literal. The final string should be "Blueberry Smoothie: $4.99".

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

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

Bummer: Make sure you're including : $ immediately after type and before price.

16 Answers

Steven Parker
Steven Parker
231,154 Points

When posting code to the forum, use Markdown formatting to preserve the appearance. And providing a link to the challenge would be helpful also.

But without referencing the challenge itself, it looks like this code will place a space between the dollar sign and the price; but the challenge might be expecting a space between the colon and dollar sign but not before the price. Also notice that the period that ends the sentence is not part of the string to be output.

dariuszkostrzewski
dariuszkostrzewski
9,409 Points

Hi,

Exactly. The following code is correct:

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

dariuszkostrzewski thank you, blessings. John 3:16 (NIV). Jesus loves you.

This worked

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

Shanna vick-Morris
Shanna vick-Morris
6,683 Points

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

Steven Parker
Steven Parker
231,154 Points

You both need formatting for your symbols to show up. See the video linked in my original answer.

None of these are working!!

Shanna vick-Morris
Shanna vick-Morris
6,683 Points

Strange Thomas you need to use a back tick before and after my answer above.

Steven Parker
Steven Parker
231,154 Points

And the formatting I mentioned in my original answer is necessary to show the back-ticks in the forum!

yeah I'm pretty lost I'm stuck on this someone please help

I removed the concatenated string and this worked const drink = ${flavor} ${type}: $${price} ; Because const cannot be renamed you would get an error. Cant have const drink for the string and const drink for the templet literal.

Elene Akers
Elene Akers
4,161 Points

you have to delete the line above

Mike Siwik
seal-mask
.a{fill-rule:evenodd;}techdegree
Mike Siwik
Full Stack JavaScript Techdegree Student 8,483 Points

This was a fun code challenge. I see everyone using const, but

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

passes. Commenting out the above line also works

jordan gillispie
jordan gillispie
24,414 Points

The value of the third variable is an integer and its asking for you to place a $ before the third var. check your spacing as well as the necessary piece of syntax to create a template literal. ill give one more hint the syntax piece is similar to a "" I hope this helps! Best of luck

I have tried this answer in many different ways and it doesn't work

const drink = ${flavor} ${type}: $${price} ; Try this it works.

edgar robledo
edgar robledo
6,067 Points

this does not work why please explain.

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

the log is = Blueberry Smoothie: $4.99

While using template literals you can't write any thing inside ${type} for example, it only takes the variable declared try to review the Template Literal course. But this is the best way to write it :

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

Steven Parker
Steven Parker
231,154 Points

Actually, you can write any expression inside the template token. And technically, your example does work to create the intended string, but it's rather unconventional and perhaps not as easy to read.

The challenge checker is apparently looking specifically for the more conventional approach to be used, and not simply testing the end result or this would pass.

And in future, rather than post a question as an "answer" to another one, create a fresh new question for your own.

because in this one we are supposed to use `` and the whole purpose of using it is to simplify things by removing all those + signs

the answer will be

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

Steven Parker
Steven Parker
231,154 Points

It actually needs accents (backticks), not apostrophes.

This :point_right: ` … not this :point_right: '

But they won't show up in the forum unless you use formatting. See the video linked in my original answer.

Dane Edwards
Dane Edwards
675 Points

This should be right.

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

Steven Parker
Steven Parker
231,154 Points

Like PAKU and Shanna, you need formatting for your symbols to show up. See the video linked in my original answer.

i tried them all none of them work

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

Steven Parker
Steven Parker
231,154 Points

See the comments about formatting in my original answer.

Violet Sky
Violet Sky
5,224 Points

in the example, it provides the following:

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

const drink = flavor + ' ' + type + ': ' + '$' + price;

you have to delete the line 'const drink = flavor + '' + type + ':' + '$' + price; '

once you delete the line, then you can redeclare it as a template literal as follows const drink = ${flavor} ${type}: $${price};

that's it.

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

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

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

this will work :)

B V K Mahijendra
B V K Mahijendra
9,133 Points

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

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

this aint't working..

could anyone help me with this.

Steven Parker
Steven Parker
231,154 Points

Read my comments to Edgar and Pascal from Mar 10!