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) Programming AJAX Stage 2 Challenge Answer

My version of the loops

Just thought I'd share my version of the code that generates the list items. Quite proud of it!

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

for (var i = 0; i < rooms.length; i += 1) {
  roomsHTML += '<li class="' + (rooms[i].available === true ? 'empty' : 'full') + '">' + rooms[i].room + '</li>';
}

roomsHTML += '</ul>';

1 Answer

Steven Parker
Steven Parker
231,172 Points

Nice use of the ternary. :+1:   But you never need to compare a boolean to "true", so you can simplify it to this:

    rooms[i].available ? 'empty' : 'full'

Thanks for the great feedback! I suppose my thinking at the time was that the content of rooms[i].available may not necessarily be boolean. In this case it is, so yeah I should have left that out!