Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Stephen Spears
10,790 PointsAjax 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');
xhr.send();
2 Answers

Dave McFarland
Treehouse TeacherYou don't need an else if
clause. You should have both the readyState`` check AND the
statuscheck in the same conditional statement. Use
&&``` to test that two conditions are both correct:
if (xhr.readyState === 4 && xhr.status === 200)

Stephen Spears
10,790 PointsWow! Answering on 4th of July. Thanks Dave.