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 Stage 2 Challenge Answer

Yosif Qassim
Yosif Qassim
6,367 Points

what is wrong in my code?

var room = new XMLHttpRequest();
room.onreadystatechange = function () {
  if(room.readyState === 4 && room.status === 200) {
    var rooms = JSON.parse(room.responseText);
    var statusHTMLr = '<ul class="rooms">';
    for (var i=0; i<rooms.length; i += 1) {
if (rooms[i].available === true) {
      statusHTMLr += '<li class="full">';
      } else {
      statusHTMLr += '<li class="empty">';
      }
    statusHTMLr += rooms[i].room;
      statusHTMLr += '</li>';
    }
  statusHTMLr += '</ul>';
document.getElementById('roomList').innerHTML = statusHTMLr;
  };

};
room.open('GET', '../data/employees.json');
room.send();

          ```
Vasanth Baskaran
Vasanth Baskaran
4,333 Points

Apart from using correct JSON file, if the rooms available is true you have to give the class Name of "empty" to the list item instead of full.

Happy Coding !!!

2 Answers

LUIS BETANCOURT
LUIS BETANCOURT
11,074 Points

on room.open ('GET', '.../data/employees.json'); you forgot to change employees.json to rooms.json hope this helps

Teacher Russell
Teacher Russell
16,873 Points

https://w.trhou.se/rrd7muid5o Here's how I did it. I missed the class of "rooms" at first, and tried using the class from the first UL. Then I found it.