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

Why isn't my code working?

This is my code

var xhr = new XMLHttpRequest ();
xhr.open('GET', 'data/employees.json');
xhr.onreadystatechange = function () {
    if(xhr.readyState === 4) {
        var employees = JSON.parse(xhr.responseText);
        var statusHTML = '<ul class="bulleted">';
        for (var i=0; i<employees.length; i +=1) {
           if (employees[i].inoffice === true) {
             statusHTML += '<li class="in">';
           } else {
             statusHTML += '<li class="out">';
           }
  statusHTML += employees[i].name;
  statusHTML += '</li>';
}
statusHTML += '</ul'>;
document.getElementByID('employeeList').innerHTML = statusHTML;
    }
};

xhr.send();

I already compared line by line with the one in the finished folder and i couldn't find any error. If I copy and paste the finished one it works just fine, i'm not getting it :(

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Edgar,

You're simply missing a closing single quote on the below line, you also have a quote inside the brackets which doesn't need to be there.

statusHTML += '</ul>';

Happy coding!

Hahaha whoa that keeps happening i don't know how many minutes i was stuck there checking line by line.

Thanx Chris!

Lauren Phillips
Lauren Phillips
13,264 Points

Also, typing .getElementByID instead of .getElementById (as I tend to do, since it makes sense) can cause problems.