-
Notifications
You must be signed in to change notification settings - Fork 1
/
repos.js
42 lines (39 loc) · 1.03 KB
/
repos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
/**
* Fetch user repos
*/
const getRepos = function() {
fetch('https://api.github.com/users/andreacardybailey/repos')
.then(response => response.json())
.then(jsonData => {
extractData(jsonData);
})
.catch(error => {
console.log(`There was an error fetching your data: ${error.message}.`);
});
};
const extractData = function(jsonData) {
jsonData.forEach(repo => {
let {
name,
html_url,
created_at,
description,
} = repo;
let dateCreated = new Date(created_at);
$('.repos').append(createTemplate(name, html_url, description, dateCreated));
});
};
const createTemplate = function(name, html_url, description, dateCreated) {
let template =
`<section>
<h2><a href="${html_url}" target="_blank">${name}</a></h2>
<ul>
<li>Description: ${description}</li>
<li>Date created: ${dateCreated.getMonth()}/${dateCreated.getDate()}/${dateCreated.getFullYear()}</li>
</ul>
</section>
`;
return template;
};
$(getRepos);