Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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');

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

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.