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 Answer

Need some help.

Hello, first of all, thank you for taking the time to read this post and answer it. What I don't understand is when do we put }); and when just this }. in this code for example.

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

1 Answer

Steven Parker
Steven Parker
231,269 Points

That first one is not just a single symbol.

You have three different things there, first a close brace "}" which would end a code block started with an open brace "{", then a close parentheses ")" which would likewise end an argument list or other group of things started with an open parenthesis "(", and finally a semicolon ";" which indicates the end of a statement.

It probably just looks funny having these on a separate line and pressed together, for example this:

    btn.on( "click", function () { alert("Hi"); } );

... is the same thing as this:

    btn.on("click", function () {
        alert("Hi");
    });

That last line is the end of the anonymous function definition, the end of the argument set for "on", and the end of the statement.

Aw something else I don't think you understood what I didn't know my bad, didn't explain it very well. I understand what you explained up there but what I don't understand is when we put this }); and when we put this } Now you are gonna tell me when you open an parenthesis, but in the code provided it haves for example this code:

$.getJSON('../data/rooms.json', function(test) {

}); 

which doesn't have an opened parenthesis, why ?

Steven Parker
Steven Parker
231,269 Points

Sure it does, you must have overlooked it:

$.getJSON('../data/rooms.json', function(test) {
//       ^ open parenthesis                    ^ open brace
});   // <-- close brace, close parenthesis, semicolon

Hehehe thank you very much, Steve.

Alright, I will try to remember to mark my questions closed :) thanks again!