JavaScript AJAX Basics (retiring) Programming AJAX Stage 2 Challenge Answer

What is wrong with this code?

Hi, I can't seem to find out what is wrong with my Javascript code, some help would be appreaciated!

// Step 1 - Create request object.
var request = new XMLHttpRequest();

// Step 2 - Create callback function, will be invoked when a request has been received.
request.onreadystatechange = function () {

  if (request.readyState === 4) {

    rooms = JSON.parse(request.responseText);
    setHTML = '<ul class="rooms">'

    for (var i = 0; i <rooms.length; i += 1) {

      if(rooms[i].available == true ) {
        setHTML += '<li class="empty">';
      }
      else {
        setHTML += '<li class="full">';
      }
      setHTML += rooms[i].room;
      setHTML += '</li>';
    }

    setHTML = '</ul>';
    document.getElementById('roomList').innerHTML = setHTML;
  }

}

//Step 3 - Making the request object.
request.open('GET', '../data/rooms.json');

//Step 4 - Sending the object
request.send();

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 46,150 Points

Similar to what happened the last time. On line 24 you have:

   setHTML = '</ul>';

it should be

   setHTML += '</ul>';

AAARGHHHHHHH, thank you again!