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

I'm confused by a piece of this code http://imgur.com/CFi4aAh

1 Answer

Jesus Mendoza
Jesus Mendoza
23,289 Points

Hey Rostyk,

var employees = JSON.parse(xhr.responseText); /* responseText is the text that came in the ajax call. You are just parsing that content into an object. */
var statusHTML = '<ul class="bulleted">'; // This is the element created to contain the list of employees names.

// Loop trought all the employees stored in the employees variable.

/* If the employee is at the office then concatenate this string to the statusHTML variable. (It will create a list element with the class 'in' the office. */
statusHTML += '<li class="in">';
/* If the employe is not at the office then concatenate this string to the statusHTML variable.
statusHTML += '<li class="out">';

/* Now the statusHTML variable should look something like this
<ul class="bulleted">
<li class="in"> or <li class="out">
*/

// Add the employee name to the statusHTML string
statusHTML += employee[i].name;
statusHTML += '</li>';

statusHTML += '</ul>';

/* If you have 3 employees the result HTML should look something like this
<ul class="bullted">
<li class="in"> or <li class="out">
employee[0].name
</li>
<li class="in"> or <li class="out">
employee[1].name
</li>
<li class="in"> or <li class="out">
employee[2].name
</li>
</ul>
*/