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 Programming AJAX Programming AJAX Solution

Michael Davis
Michael Davis
6,992 Points

My CSS isn't being applied.

The code looks to be working when I check the console I can see the HTML is added and it is adding the class .empty/.full to the <li> but the CSS isn't being applied was there a mistake in my code?

var roomRequest = new XMLHttpRequest();
roomRequest.onreadystatechange = function () {
  if(roomRequest.readyState === 4 && roomRequest.status === 200) {
    var rooms = JSON.parse(roomRequest.responseText);
    var statusHTML = '<ul class="room">';
    for (var i=0; i<rooms.length; i += 1) {
      if (rooms[i].available === true) {
        statusHTML += '<li class="empty">';
      } else {
        statusHTML += '<li class="full">';
      }
      statusHTML += rooms[i].room;
      statusHTML += '</li>';
    }
    statusHTML += '</ul>';
    document.getElementById('roomList').innerHTML = statusHTML;
  }
};
roomRequest.open('GET', '../data/rooms.json');
roomRequest.send();
Steven Parker
Steven Parker
216,810 Points

There could be an error in the CSS, but it's not shown here. You can share an entire workspace at once if you make a snapshot of your workspace and post the link to it here.

Michael Davis
Michael Davis
6,992 Points

Here's that snapshot. If it is an issue with the CSS then it would have been a mistake from team treehouse cause they set up the CSS document.

https://w.trhou.se/w1foffy1wv

1 Answer

Steven Parker
Steven Parker
216,810 Points

Thanks to the snapshot and seeing the whole project, it was much easier to spot the issue.

As seen in the video, the CSS is targeting items in a list with the class "rooms" (plural), but this code is constructing the list with the class "room" (singular).

Michael Davis
Michael Davis
6,992 Points

so you are saying the statusHTML variable should be written like this?

var statusHTML = '<ul class="rooms">';

Steven Parker
Steven Parker
216,810 Points

That's what is shown in the video, and what the CSS is looking for.