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

Would this be a correct solution?

I'm not able to fetch the employees.json file in workspaces for whatever reason so I'm not sure if this solution is working or not. Could anybody look at this and tell if this code would run as intended? Thanks!

const xhr = new XMLHttpRequest();
xhr.readstatechange = function() {
  if (xhr.readyState === 4) {
    const employees = JSON.parse(xhr.responseText);
    let html = '<ul class="bulleted">';
    for (i=0;i<employees.length;i++) {
      let name = employees[i].name;
      let isInOffice = employees[i].inOffice ? 'in' : 'out';
      html += `<li class="${isInOffice}">${name}</li>`;
    }
    html += '</ul>;
  }
};
xhr.open('GET','data/employees.json');
xhr.send();

1 Answer

Jesus Mendoza
Jesus Mendoza
23,289 Points

Did you fix the last assigment to the html variable? Its missing a closing '

    html += '</ul>';