Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

The 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;

Hi 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

1 Answer

Steven Parker
Steven Parker
216,083 Points

This 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?