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 trialMichael Davis
6,992 PointsMy 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();
Michael Davis
6,992 PointsHere'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.
1 Answer
Steven Parker
231,268 PointsThanks 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
6,992 Pointsso you are saying the statusHTML variable should be written like this?
var statusHTML = '<ul class="rooms">';
Steven Parker
231,268 PointsThat's what is shown in the video, and what the CSS is looking for.
Sheridan Injeeli
Full Stack JavaScript Techdegree Graduate 16,137 PointsThank you, this worked
Steven Parker
231,268 PointsSteven Parker
231,268 PointsThere 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.