-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos.js
54 lines (50 loc) · 1.18 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
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Fetch user repos
*/
const getRepos = function() {
fetch('https://api.github.com/users/andreacardybailey/repos')
.then(response => response.json())
// 👇 You MUST work with the data HERE 👇
.then(jsonData => {
extractData(jsonData);
})
.catch(error => console.log(error));
};
/**
* Extract data to be used on page
* @param data - the JSON data
*/
const extractData = function(data){
data.forEach(repo => {
let {
name,
html_url,
created_at,
description
} = repo;
let dateCreated = new Date(created_at);
$('.repos').append(createTemplate(name, html_url, dateCreated, description));
});
};
/**
* Create HTML template for each result
* @param {string} repo_name
* @param {string} url
* @param {Date} created_at
* @param {string} description
*/
const createTemplate = function(repo_name, url, date, description) {
let template = `
<section>
<h2><a href="${url}">${repo_name}</a></h2>
<ul>
<li>Description: ${description}</li>
<li>
Date created: ${date.getMonth()}/${date.getDate()}/${date.getFullYear()}
</li>
</ul>
</section>
`;
return template;
};
$(getRepos);