Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e759015

Browse files
committed
change to homework
1 parent a649033 commit e759015

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

homework/src/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<title>HYF-GITHUB</title>
1414
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
1515
<link rel="stylesheet" href="./style.css">
16-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
1716
</head>
1817

1918
<body>

homework/src/index.js

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
cb(null, xhr.response);
1111
} else {
1212
cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));
13+
console.log("Hello error");
1314
}
1415
};
1516
xhr.onerror = () => cb(new Error('Network request failed'));
@@ -30,7 +31,6 @@
3031
return elem;
3132
}
3233

33-
3434

3535
function main(url) {
3636
while (root.firstChild) {
@@ -41,58 +41,67 @@
4141
let newArray = [];
4242
let forkArray = [];
4343
let languageArray = [];
44+
let descriptionArray = [];
4445
let htmlArray = [];
4546
let contributorsArray = [];
4647
for (let i = 0; i < data.length; i++){
47-
newArray.push(data[i].name);
48-
newArray.sort();
49-
forkArray.push(data[i].forks);
50-
languageArray.push(data[i].language);
51-
contributorsArray.push(data[i].contributors_url);
52-
contributorsArray.sort();
53-
htmlArray.push(data[i].html_url);
54-
htmlArray.sort();
55-
}
56-
57-
let app = document.getElementById('root');
58-
const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' });
59-
const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'});
60-
const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" });
61-
const container = createAndAppend('div', app, {class: 'container'});
62-
const card = createAndAppend('div', container, {text: "Description of this repository ", class: 'card'});
63-
const ul = createAndAppend('ul', card, {id: "myUl", });
64-
const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' });
65-
const contributorsContainer = createAndAppend('div', root, { class: 'container'})
66-
const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'});
67-
const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'});
48+
newArray.push(data[i].name);
49+
newArray.sort();
50+
descriptionArray.push(data[i].description);
51+
forkArray.push(data[i].forks);
52+
languageArray.push(data[i].language);
53+
contributorsArray.push(data[i].contributors_url);
54+
contributorsArray.sort();
55+
htmlArray.push(data[i].html_url);
56+
htmlArray.sort();
57+
}
58+
59+
let app = document.getElementById('root');
60+
const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' });
61+
const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'});
62+
const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" });
63+
const container = createAndAppend('div', app, {class: 'container'});
64+
const card = createAndAppend('div', container, {text: "Information about this repository: ", class: 'card'});
65+
const ul = createAndAppend('ul', card, {id: "myUl", });
66+
const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' });
67+
const contributorsContainer = createAndAppend('div', root, { class: 'container'})
68+
const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'});
69+
const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'});
6870

6971

7072

71-
data.forEach((repo) => {
72-
for (let i = 0; i < newArray.length; i++) {
73-
createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]});
74-
}
75-
});
73+
data.forEach((repo) => {
74+
for (let i = 0; i < newArray.length; i++) {
75+
createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]});
76+
}
77+
});
7678

77-
function removeNodes(container){
78-
while (ul.hasChildNodes()) {
79-
ul.removeChild(ul.firstChild);
80-
}
81-
while (contributorsUl.hasChildNodes()) {
82-
contributorsUl.removeChild(contributorsUl.firstChild);
79+
function removeNodes(container){
80+
while (ul.hasChildNodes()) {
81+
ul.removeChild(ul.firstChild);
82+
}
83+
while (contributorsUl.hasChildNodes()) {
84+
contributorsUl.removeChild(contributorsUl.firstChild);
85+
}
8386
}
84-
}
8587

86-
selectList.onchange = function(selectedIndex){
87-
createAndAppend('li', ul, { text: "Repository: " + newArray[this.selectedIndex], class: 'nameInContainer', function: removeNodes()});
88-
createAndAppend('a', ul, { text: htmlArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
89-
createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
90-
createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
91-
createAndAppend('li', contributorsUl, { text: contributorsArray[this.selectedIndex], class: 'contributorsInContainer'});
92-
}
88+
selectList.onchange = function(selectedIndex){
89+
let RepoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()});
90+
createAndAppend('a', RepoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
91+
createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'});
92+
createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
93+
createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
94+
createAndAppend('li', contributorsUl, { text: contributorsArray[this.selectedIndex], class: 'contributorsInContainer'});
95+
}
96+
});
97+
/*
98+
fetchJSON( theContributors_URL, (err, data) => {
99+
let theContributorsUrl = [];
100+
for (let i = 0; i < data.length; i++){
93101
94-
});
95-
}
102+
}
103+
});*/
104+
}
96105

97106
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
98107
const theContributors_URL = 'https://api.github.com/repos/HackYourFuture/contributors';

0 commit comments

Comments
 (0)