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 trialMahmoud Nasser
5,507 PointsTemplate Literals WorkShop
function createPlanetHTML(planet) {
return `
<div class="card">
<div>
<img src="img/planet.name.jpg" alt="planet.name">
</div>
<h2> ${ planet.name} </h2>
<p>${planet.description } </p>
<h3>Planet Profile</h3>
<ul>
<li><strong>Diameter: </strong> ${planet.diameter}</li>
<li><strong>Moons: </strong> ${ planet.moons} </li>
<li><strong>Temperature: </strong> ${ planet.temp} </li>
<li><strong>Orbit Period: </strong>${ planet.orbitDays} days ${planet.orbitYears} years </li>
</ul>
<p> ${planet.facts} </p>
</div>;
`
}
why this we didnt put template literals before <h3> ???
3 Answers
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsHi Mahmoud,
You could certainly put the placeholders before the h3 element if you wanted to. The h3 element is just static text that shows the "Planet Profile" area of the web page.
In other words, it's just personal preference :).
I hope that helps! Let me know if you have any more questions!
Mahmoud Nasser
5,507 Pointsdo u mean by static that its value doesnt change ?? thats why we enclose all of the planet properties with the dollar sign because properties can have many values ??
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsThe template literal as a whole is dynamic because of the placeholders, the ${}, but the h3 element in particular is static since there are no placeholders in that element.
Does that help clarify?
Mahmoud Nasser
5,507 Pointsyeah thanks chris it is great
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot a problem :)!
Mahmoud Nasser
5,507 PointsMahmoud Nasser
5,507 Pointsthanks chris :) ,but aint we concatenating all of html tags in the html and returning it so we should have interpolated the tag <h3> right ??
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot a problem, Mahmoud!
I reworded my answer to make it clearer. The entire HTML string that your function is returning is the template literal. Below is the first sentence of the Template Literals MDN article:
Template literals are string literals allowing embedded expressions.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Therefore, the h3 element is part of the template literal. The placeholders (the ${}) are where the planet properties are inserted via interpolation. So, the h3 element is not being interpolated, it's static text in the template literal.
Does that help answer your question? Let me know if I didn't understand your question!