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 trialRobert Leonardi
17,151 PointsAlternative solution to Employee List
Please don't hesitate to comment or suggest. Thanks
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4){
if(xhr.status === 200 ){
let employees = JSON.parse(xhr.responseText);
let add_ul = document.createElement("ul");
add_ul.className = "bulleted";
document.getElementById("employeeList").append(add_ul);
employees.forEach(function(employee){
let add_li = document.createElement("li");
add_li.innerText = employee["name"];
if(employee["inoffice"] == true){add_li.className="in"}else{add_li.className="out"};
add_ul.append(add_li);
});
} else {
alert("Error "+xhr.status+" due to "+xhr.statusText);
}
}
};
xhr.open('GET','data/employees.json');
xhr.send();
1 Answer
ywang04
6,762 PointsThe logic is the same. You use DOM to manipulate. What I am wondering is which way is better in terms of performance.