This forum is now read-only. Please use our new forums at discuss.codecademy.com.

How to use APIs with JavaScript Forum

View Course » View Exercise

1500 points
519932bf46785176fa002a6b_367696470
Submitted by
quantumm
over 4 years ago

What is wrong with my code?

The instructions seem clear enough to me, but still I can't manage to pass the lesson. Here is what I have written:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/doesnt_exist", false);
xhr.send();
// Add your code below!
xhr.status();
console.log(xhr.status);

It responds with this error:
[Exception... "Failure" nsresult: "0x80004005 (NSERRORFAILURE)" location: "JS frame :: https://www.codecademy.com/assets/repl.html :: :: line 3" data: no]
Oops, try again.
Did you console.log(xhr.status)?

What am I doing wrong?


3 votes

permalink

Actually, there is a new user named doesnt_exist, so the link http://www.codecademy.com/doesnt_exist is valid and you should change it a little bit to get a 404 error instead of 200.
This worked for me :

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/doesnt_exist.htm",false);
xhr.send();
console.log(xhr.status);

740 points
951daa310b288b9500fa5bb8f4c4d2a1?s=140&d=retro
Submitted by
Imane Fateh
almost 4 years ago


0 votes

permalink

xhr.status
You have to remove the brackets. I think the brackets are reserved for methods/ functions im not sure since i just started but that would be my guess to why it is not working.

562 points
0e8eec8f737870de7751f8ebe7683eed?s=140&d=retro
Submitted by
cronohl
over 4 years ago

1 Comment

519932bf46785176fa002a6b_367696470 quantumm about 4 years ago

Thank you


0 votes

permalink

You just need to remove "xhr.status();". I believe it just wants the console.log(xhr.status);. Like this:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/doesnt_exist", false);
xhr.send();
console.log(xhr.status);

827 points
4863a9daccdf7e09bd711f8ab099139a?s=140&d=retro
Submitted by
Tanner Hubbert
about 4 years ago

2 Comments

519932bf46785176fa002a6b_367696470 quantumm about 4 years ago

Thank you

Picture Ralph Schreurs about 4 years ago

Thanks, I made the same mistake


0 votes

permalink

This work ("POST" instead of "GET"):

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://www.codecademy.com/doesnt_exist", false);
xhr.send();
console.log(xhr.status);

817 points
8f7066785936a3dc0e39731d10361b0a?s=140&d=retro
Submitted by
Bine Intentionat
almost 4 years ago


-10 votes

permalink

well you need to pay atteion

0 points
Bb154844e1069c9f25a131119ff27d69?s=140&d=retro
Submitted by
omar345
about 4 years ago