JavaScript Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

Alejandro Bryan
Alejandro Bryan
9,549 Points

I'm having a lot of problems with the Promises call.

hi guys! I'm having a lot of problems with promise call, even if I write the same code as the teacher, it seems to be a broken link, I feel me somehow like a stupid person. maybe I'm gut enough to learn how to program.

Steven Parker
Steven Parker
201,932 Points

It might be something as simple as a little typo. Show your code and we can take a look. Even better, make a snapshot of your workspace and post the link to it here.

5 Answers

Steven Parker
Steven Parker
201,932 Points

This one's not your fault. This issue is due to two 3rd-party API's having a disagreement about spelling. :see_no_evil: An improvement would be to display the original name with a message indicating that the profile wasn't found. Code that could automatically resolve this kind of thing in a generic way would be rather complex.

But if you don't mind applying a temporary (and potentially brittle) fix for these specific cases, you could just translate the names as you look up the profiles:

function getProfiles(json) {
  const profiles = json.people.map( person =>
    getJSON(wikiUrl + person.name.replace("Anatoly", "Anatoli")
                                 .replace("Chris", "Christopher"))
  ); 
  return Promise.all(profiles);
}
Alejandro Bryan
Alejandro Bryan
9,549 Points

I appreciated your help. thanks a lot

Murilo de Melo
Murilo de Melo
13,927 Points

Hi Alejandro, tnx for your question. I'm getting the same problem. And tnx Steven too for the help :) That's very bad considering that a huge desaster because of such a mere issue of spelling.

Mike Campbell
Mike Campbell
10,974 Points

Actually, that solution looks pretty good. It only works if you know it's misspelled though. I scratched my head for a while when I was trying to figure it out.