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 (retiring) jQuery and AJAX The Office Status Project Revisited

Where is the first employee from the employees.json file, named Aimee?

In both Dave's output as well as my own, the first employee gets dropped. Well, actually in my own output I get her first name with no styling and no in/out of office status. In Dave's output she is gone completely. The first employee in his output is "Amit" who is out of the office. So where is "Aimee"? Do we have different employees.json data files?

In my output "Amit" appears along with all the other employees correctly styled, but after the unstyled "Aimee". My employees.json file looks fine. "Aimee" is first, but if I swap her with "Amit", then "Amit" is unstyled with no in/out of office status, but "Aimee" then looks fine along with all the rest of the employees. Any ideas?

Here is my code:

$(document).ready(function() {
  var url = "../data/employees.json";  
  $.getJSON(url, function (response) {
     var statusHTML = '<ul class="bulleted"';
     $.each(response,function(index, employee){
       if(employee.inoffice === true) {
          statusHTML += '<li class="in">';
        } else {
            statusHTML += '<li class="out">';
        }
        statusHTML += employee.name + "</li>";
     });
     statusHTML += "</ul>";
     $("#employeeList").html(statusHTML);
   }); // end getJSON
 }); // end ready

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

Take a look at this line:

 var statusHTML = '<ul class="bulleted"';

You didn't close this element, so chances are the first item reads like this in the html:

<ul class="bulleted" <li>
Amit</li>
<li>Aimee</li>

So the first Amit is unstyled because it isn't really a list item yet, with an orphaned </li> closing tag after it, which the browser just ignores.

Ah! Thanks. I didn't catch that. I still wonder why in Dave's video his output drops Aimee completely? I suppose he could have been using a slightly different json data file without a first employee of Aimee?

WAIT! Now I see. I just started the next AJAX/jQuery lesson and lo and behold, the employees.json data file does not have an employee named "Aimee" in it. So, indeed, the instructor's data files from the last lesson were slightly different than the student's. Alles klar!