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
11 changes: 11 additions & 0 deletions 3-fetch-api-ajax/fetch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetch</title>
</head>
<body>
<script src="fetch.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions 3-fetch-api-ajax/fetch.js
Original file line number Diff line number Diff line change
@@ -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);
Comment on lines +16 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you need this timeout?

Comment on lines +16 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
setTimeout(() => {
resolve(githubUser);
}, 3000);
resolve(githubUser);

});
}

loadJson('https://api.github.com/repos/push-dev/frontend-roadmap/commits')
.then(githubUser => githubUser[0].author)
.then(showAvatar)