diff --git a/3-fetch-api-ajax/fetch.html b/3-fetch-api-ajax/fetch.html new file mode 100644 index 0000000..1a66956 --- /dev/null +++ b/3-fetch-api-ajax/fetch.html @@ -0,0 +1,11 @@ + + + + + + Fetch + + + + + \ No newline at end of file diff --git a/3-fetch-api-ajax/fetch.js b/3-fetch-api-ajax/fetch.js new file mode 100644 index 0000000..1374c54 --- /dev/null +++ b/3-fetch-api-ajax/fetch.js @@ -0,0 +1,24 @@ +function loadJson(url) { + return fetch(url) + .then(response => response.json()); +} + +function showAvatar(githubUser) { + return new Promise(function(resolve, reject) { + let img = document.createElement('img'); + let tittle = document.createElement('h1'); + img.src = githubUser.avatar_url; + img.className = "promise-image"; + tittle.innerHTML = `Name: ${githubUser.login}`; + document.body.append(tittle); + document.body.append(img); + + setTimeout(() => { + resolve(githubUser); + }, 3000); + }); +} + +loadJson('https://api.github.com/repos/push-dev/frontend-roadmap/commits') +.then(githubUser => githubUser[0].author) +.then(showAvatar) \ No newline at end of file