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 trial

JavaScript Asynchronous Programming with JavaScript Exploring Async/Await Convert Promise Handling to Async/Await

WikiUrl still isn't clicking to me.

How is he using each name property from the data URL to get information from the wikiURL? I can't fully understand it?

rydavim
rydavim
18,814 Points

Can you post a workspace snapshot, or a snippet of the code you're talking about? You can use the camera icon in the top right of your workspace to link to a copy of your full coding environment.

2 Answers

rydavim
rydavim
18,814 Points
function getProfiles(json) {
  json.people.map( person => { 
    getJSON(wikiUrl + person.name, generateHTML); 
  }); 
}

I've only had a brief chance to take a look at this, but it looks like you're passing in a JSON array and then using the contents to create a new array with the detailed information associated with the people in the array. So you have a list of people, and you're using that in order to fetch more information about each of them to populate your webpage.

So for each person in the original array, you're using the value of person.name to generate a new url with which to get the detailed data. So if you've got a person called "summer" you would get a url of https://en.wikipedia.org/api/rest_v1/page/summary/summer. You're using the JSON from that page to populate information into the HTML sections you're creating with generateHTML.

Without the full program in front of me, I'm having trouble being more detailed. But if you have any additional questions, I'll do my best to answer them.

just that piece alone helps me put it together, thank you!

const astrosUrl = 'http://api.open-notify.org/astros.json'; const wikiUrl = 'https://en.wikipedia.org/api/rest_v1/page/summary/'; const peopleList = document.getElementById('people'); const btn = document.querySelector('button');

function getJSON(url, callback) { const xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onload = () => { if(xhr.status === 200) { let data = JSON.parse(xhr.responseText); return callback(data); } }; xhr.send(); }

function getProfiles(json) { json.people.map( person => { getJSON(wikiUrl + person.name, generateHTML);
}); }

// The function getProfiles, I can't fully grasp it.