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) jQuery and AJAX Stage 3 Challenge

Sean Flanagan
Sean Flanagan
33,235 Points

Stage 3 challenge - my solution

Hi.

This is my answer.

$(document).ready(function () {
  $.getJSON('../data/rooms.json', function (data) {
    var statusHTML = '<ul class="bulleted">';
    $.each(data,function (index, room) {
      if (room.available === true) {
        statusHTML +='<li class="available">';
      } else {
        statusHTML +='<li class="unavailable">';
      }
      statusHTML += room.name + '</li>';
    });
    statusHTML += '</ul>';
    $('#roomList').html(statusHTML)
  }); // end getJSON
}); // end ready

I would appreciate constructive feedback.

1 Answer

Steve Gallant
Steve Gallant
14,943 Points

The first question is: did it work as you expected? I just completed the example - mine works and I did several things differently.

  1. I used different variables in this code block to avoid conflicting with those already established for the employees list.
  2. My ul class is "rooms" rather than "bulleted" to get the proper styling.
  3. The classes for the li elements should be "full" and "empty" to match the .json file.
  4. I think you are missing the room name/number before the closing li tag.

Hope it helps! Steve