Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions 3-fetch-api-ajax/fetch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<header>THIS IS AN API'S INFORMATION</header>
<body>
<script src="fetch.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions 3-fetch-api-ajax/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

'use strict'

const URLS = 'https://api.github.com/repos/push-dev/frontend-roadmap/commits';

function loadJson(url) {
return fetch(url)
.then(response => response.json());
}

async function showAvatar(githubUser) {
return new Promise(function(resolve, reject) {
let img = document.createElement('img');
let paragraph = document.createElement('h1');
img.src = githubUser.avatar_url;
img.className = "promise-image";
paragraph.innerHTML = 'Name: ' + githubUser.login;
document.body.append(paragraph);
document.body.append(img);
Comment on lines +13 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement this exercise without creating these elements, they should be already present on the HTML and you just need to use the reference to them.


setTimeout(() => {
resolve(githubUser);
}, 5000);
});
}

loadJson(URLS).then(githubUser => githubUser[0].author).then(showAvatar);