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! While you're at it, check out some resources Treehouse students have shared here.
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 trialRyan Giusti
18,082 PointsMore 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
231,236 PointsThis 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.
Viktor Lovgren
6,241 PointsThere 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
Front End Web Development Techdegree Graduate 20,330 PointsI 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
8,071 PointsI 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
Zimri Leijen
11,835 PointsZimri Leijen
11,835 Pointsto add to that, some of the names are ambiguous, and will return some kind of "error" as well.
Ryan Giusti
18,082 PointsRyan Giusti
18,082 PointsNoted! I'll give it a shot at some point.