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 trialEamon Jurdzis
8,849 PointsMy 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
231,268 PointsNice use of the ternary. But you never need to compare a boolean to "true", so you can simplify it to this:
rooms[i].available ? 'empty' : 'full'
Eamon Jurdzis
8,849 PointsEamon Jurdzis
8,849 PointsThanks 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!