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

difference btw creating node with Appendchild vs brute text ex : '<li></li>'

So the teacher solution create all the li with back quotes but I appendchild and create element. here is my code : function builder (data) { const div = document.getElementById("employeeList"); const ul = document.createElement("UL");

ul.classList.add("bulleted");
div.appendChild(ul);
for (let i = 0; i < data.length; i++)
{
    let li = document.createElement("LI");

    if (data[i].inoffice == true)
        li.classList.add("in");
    else
        li.classList.add("out");
    li.textContent = data[i].name;
    ul.appendChild(li);
}

}; Which method is better and why? Thanks in advance

1 Answer

Steven Parker
Steven Parker
231,248 Points

You forgot to provide a reference to the course example, but just in general there are often multiple ways to accomplish a specific thing.

In more complex code you may find that one method might save some steps or otherwise make the code more efficient compared to the alternatives. But in simple cases, such as many of the course examples, it may not really make a difference which method you use.