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!

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

General Discussion

Stephen Spears
Stephen Spears
10,790 Points

Ajax Callbacks Code Challenge 4 of 4

I'm not sure why I can't pass this Code Challenge. This code works on the preview but it won't let me pass.

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
  if (xhr.readyState === 4){
    document.getElementById('sidebar').innerHTML = xhr.responseText;
  } else if (xhr.status === 200){}
xhr.open('GET', 'sidebar.html');

2 Answers

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Stephen Spears

You don't need an else if clause. You should have both the readyState`` check AND thestatuscheck in the same conditional statement. Use&&``` to test that two conditions are both correct:

if (xhr.readyState === 4 && xhr.status === 200)
Stephen Spears
Stephen Spears
10,790 Points

Wow! Answering on 4th of July. Thanks Dave.