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 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
229,744 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
229,744 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
229,744 Points

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