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 trialAntonio Ascue Avalos
3,023 PointsThe multiple line string with tilde doest not work for me
For some reason, this does not work for as it is quite annoying since this is pretty straight forward. I have either pressed the incorrect tilde ` or there something with the browser which is Chrome version 71.0.3578.98. Lastly, it can be something with the code I am missing up with, without noticing it.
The HTML of both lists does not show up on the page. But the fruitList do when loaded alone.
const fruitList =
"<ul>" +
"<li>Kiwi</li>" +
"<li>Lime</li>" +
"<li>Pineapple</li>" +
"</ul>";
const vegetableList = `
<ul>
<li>Potato</li>
<li>Onion</li>
<li>Broccoli</li>
</ul>
`;
document.querySelector('.fruits').innerHTML = fruitList;
document.querySelector('.vegetables').innerHTML = vegetableList;
1 Answer
Steven Parker
231,122 PointsThis code seems fine in itself, but needs HTML to go with it to work. I tested it using this HTML:
<div class="fruits"></div>
<div class="vegetables"></div>
Both lists displayed as expected. What does the actual HTML look like?
Ajay Prasannan
16,002 PointsAjay Prasannan
16,002 PointsHi Antonio,
I copied the template string const into my Chrome developer tools console, and it worked, and I could access the variable and see the template. I'm on Chrome 72.0.3626.121, but I'd expect it to be fine on your version as well.
Any visible error messages, or is it just that you're not getting the behaviour you expect?
Might be worth double-checking your accompanying HTML, along with the selectors you're using to insert the HTML; there should be elements in the HTML with the correct class applied in order for the JS to work.
I did a very quick test inserting the template string into an arbitrary element with
document.querySelector()
, and it worked fine.Hope this helps,
Ajay