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 AJAX Basics Programming AJAX Processing JSON Data

Ian Simpson
seal-mask
.a{fill-rule:evenodd;}techdegree
Ian Simpson
Full Stack JavaScript Techdegree Student 8,509 Points

Different approach...?

I jumped the gun a little on this section and went ahead and wrote my callback without watching the whole video. Instead of using one variable to write the html I used createElement and the for loop like so...

if (xhr.readyState === 4) { var employees = JSON.parse(xhr.responseText); const div = document.getElementById('employeeList'); const ul = document.createElement('ul'); ul.className = "bulleted"; div.appendChild(ul); for (let i = 0; i < employees.length; i++) { const li = document.createElement('li'); li.textContent = ${employees[i].name}; if (employees[i].inoffice) { li.className = "in"; } else { li.className = "out"; } ul.appendChild(li); } }

It worked perfectly and I found this easier to understand. Is there a reason I shouldn't have done it this way?