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.

JavaScript Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Implement a Callback

Ryan Giusti
Ryan Giusti
18,082 Points

More of an api issue, but currently there is an astronaut who's name differs from the api data and wiki article

Currently there is a man name Anatoli Ivanishin, but the api returns "Anatoly" for his first name. I was still able to get his name to populate by adding an if statement to check for his misspelled name specifically. I'm not sure if there's a better way to implement this, but I also wanted to put this out there in case anyone else encounters the same thing. Treehouse can't control who's in space or if there are discrepancies between data in one api or another, but I did find this to be a great emerging exercise in determining what the issue was and solving it (kinda).

4 Answers

Steven Parker
Steven Parker
210,108 Points

This came up recently in another question, where I suggested that this might be a good opportunity for a bonus exercise to create some code to make errors in looking up details a bit more graceful (like display the name and a "friendly" error message).

To attempt to fix a misspelling, but in a generic way, you could convert the names into soundex keys and look for a match using those. But that's a far more advanced exercise.

But if you don't mind applying a temporary fix for these specific cases, you could just translate from one spelling to another. See the example code posted by Victor below.

to add to that, some of the names are ambiguous, and will return some kind of "error" as well.

Ryan Giusti
Ryan Giusti
18,082 Points

Noted! I'll give it a shot at some point.

Viktor Lovgren
Viktor Lovgren
6,241 Points

There is surely a better way to fix this that can apply to more cases, but right now these names need fixing: Chris Cassidy, Anatoly Ivanishin

btn.addEventListener("click", () => {
  getJSON(astrosUrl, (json) => {
    json.people.map((person) => {
      if (person.name === "Anatoly Ivanishin") {
        person.name = "Anatoli Ivanishin";
      }
      if (person.name === "Chris Cassidy") {
        person.name = "Christopher Cassidy";
      }
      getJSON(wikiUrl + person.name, generateHTML);
    });
  });
});
C.J. O'Leary
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
C.J. O'Leary
Front End Web Development Techdegree Graduate 20,041 Points

I had a similar issue, except this time the astronaut had the same name as a Russian football/soccer player so the wikiUrl was a disambiguation page. I did a simple if...else and it seemed to resolve the issue

function getProfiles(json) {
  console.log(json);
  json.people.map(person => {
    if (person.name === 'Sergey Ryzhikov') {
      getJSON(wikiUrl + person.name + `_(cosmonaut)`, generateHTML);
    } else {
      getJSON(wikiUrl + person.name, generateHTML);
    }
  });
}
ilovecode
ilovecode
8,070 Points

I copied the JSON data from the api and created a .json file and pasted the data in and just fixed the spelling of the name and used that instead of the api, just for the sake of the videos