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,266 Points

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

    html += '</ul>';