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 trialSean Flanagan
33,235 PointsCan't work this out
Hi.
I've completed the Stage in the ES2015 course about template literals and string interpolation but I can't figure this challenge out.
Are there any clues people can offer without giving me the whole solution please?
5 Answers
Steven Parker
231,269 PointsSure, I resist giving code spoilers anyway. Here's a few hints:
- template literals start and end with a backtick/apostrophe
- template literals can take up multiple lines
- JavaScript object values can be substituted by enclosing their names in brackets with a dollar-sign in front
- the values can be simple variables or object properties
Sean Flanagan
33,235 PointsThe function name is createPlanetHTML, not createMarsHTML, yet I've given the image file path:
<div>
<img src="img/mars.jpg" ${mars(name)} + '.jpg" alt="'${mars(name)} '">'
</div>
This is supposed to be the template for the planets, yet I treated it as if it were one of the planets.
Oops. I also seem to remember struggling with the last list item because it's the longest. It made it harder for me to read.
Steven Parker
231,269 PointsWhen I mentioned "dot notation" I was talking about how you access properties in the object. You put the property name next to the object with a dot (period) in between. Putting a property name in parentheses is not proper syntax for property access.
Also, the original function worked with a parameter passed in named "planet". Changing that to a specific planet will prevent the function from being useful for printing out planet data in general.
Give it one more try, and if it's still not working, it might be time to move on to the next video and see a sample solution.
Sean Flanagan
33,235 PointsYes I tried it, but nothing happened.
Steven Parker
231,269 PointsAhh... well that's the clue that it might need a bit more work.
Sean Flanagan
33,235 PointsI've taken what you said about dot notation under advisement.
Here's another snapshot of how my code is now:
I previewed it and this time it's showing.
Thank you
Sean
Steven Parker
231,269 PointsClose enough to print! But you still have a few places with a specific instance name instead of the argument "planet".
Sean Flanagan
33,235 PointsI've just cleared those up. And I've given you an upvote and Best Answer for your help.
Thanks Steven and happy coding to you too!
Sean :-)
Sean Flanagan
33,235 PointsSean Flanagan
33,235 PointsHi Steven.
Thanks for your tips; they came in handy.
I've not looked at Guil's solution. Here's my attempt:
https://w.trhou.se/bewv1kyz71
Constructive feedback appreciated.
Cheers
Sean
Steven Parker
231,269 PointsSteven Parker
231,269 PointsDid you try this out? It looks like you may still need to work on how you specify the various properties being printed. The "dot notation" still applies in a template just as it does in the script.