Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit bf39a29

Browse files
committed
modified homework
1 parent 4cfd068 commit bf39a29

4 files changed

Lines changed: 43 additions & 28 deletions

File tree

homework/DogPhoto/DogPhotoGallery.html

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
text-align: center;
1111
background-color: whitesmoke;
1212
}
13-
button{
13+
ul{
14+
list-style: none;
15+
}
16+
img {
17+
width: 250px;
18+
height: 250px;
19+
}
20+
#axiosBtn, #xhrBtn{
1421
padding: 10px;
1522
margin: 10px;
1623
font-weight: 600;
@@ -19,23 +26,18 @@
1926
</head>
2027
<body>
2128
<dvi>
22-
<button id="btn">Get by Axios</button>
23-
<button id="btn2">Get by XHR</button>
29+
<button id="axiosBtn">Get by Axios</button>
30+
<button id="xhrBtn">Get by XHR</button>
2431
<div id="main">
25-
<ul>
26-
<li>
27-
28-
</li>
29-
</ul>
3032
</div>
3133

3234
</dvi>
3335

3436
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
3537
<script>
3638
let mainDiv = document.getElementById('main')
37-
let getByAxios= document.getElementById('btn');
38-
let getByXHR = document.getElementById('btn2');
39+
let getByAxios= document.getElementById('axiosBtn');
40+
let getByXHR = document.getElementById('xhrBtn');
3941
getByAxios.addEventListener('click', fetchByAxios);
4042
getByXHR.addEventListener('click', fetchByXHR);
4143

@@ -44,15 +46,16 @@
4446
axios
4547
.get('https://dog.ceo/api/breeds/image/random')
4648
.then((res) => {
47-
mainDiv.innerHTML = '';
49+
let ul = document.createElement("ul");
50+
let li = document.createElement("li")
4851
let img = document.createElement('img');
4952
img.src = res.data.message;
50-
img.style.width = '400px';
51-
img.style.height = '400px';
52-
let h1 = document.createElement('h1');
53-
h1.innerText = 'Show by Axios';
54-
mainDiv.appendChild(h1);
55-
mainDiv.appendChild(img);
53+
let h2 = document.createElement('h2');
54+
h2.innerText = 'Show by Axios';
55+
li.appendChild(img);
56+
ul.appendChild(li);
57+
mainDiv.appendChild(h2);
58+
mainDiv.appendChild(ul);
5659
})
5760
.catch((err) => console.error(err));
5861
}
@@ -62,16 +65,20 @@
6265
let getByXhr = new XMLHttpRequest();
6366
getByXhr.responseType = 'json';
6467
getByXhr.onreadystatechange = function() {
65-
if (this.readyState === 4 && this.status === 200) {
66-
mainDiv.innerHTML = '';
68+
if (this.readyState === XMLHttpRequest.DONE && this.status ===200) {
69+
let ul = document.createElement("ul");
70+
let li = document.createElement("li")
6771
let img = document.createElement('img');
6872
img.src = getByXhr.response.message;
69-
img.style.width = '400px';
70-
img.style.height = '400px';
71-
let h1 = document.createElement('h1');
72-
h1.innerText = 'Show by XHR';
73-
mainDiv.appendChild(h1);
74-
mainDiv.appendChild(img);
73+
let h2 = document.createElement('h2');
74+
h2.innerText = 'Show by XHR';
75+
li.appendChild(img);
76+
ul.appendChild(li);
77+
mainDiv.appendChild(h2);
78+
mainDiv.appendChild(ul);
79+
}
80+
else if (this.status >= 400 && this.status < 500){
81+
console.error("There is an error");
7582
}
7683
};
7784
getByXhr.open('GET', 'https://dog.ceo/api/breeds/image/random', true);

homework/Humor/Programmerhumor.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
let getByXhr = new XMLHttpRequest();
4343
getByXhr.responseType = 'json';
4444
getByXhr.onreadystatechange = function() {
45-
if (this.readyState === 4 && this.status === 200) {
45+
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
4646
console.log(getByXhr.response);
4747
let h1 = document.createElement('h1');
4848
h1.innerText = 'Show by XHR';
@@ -51,6 +51,8 @@
5151
document.body.appendChild(h1);
5252
document.body.appendChild(img);
5353
}
54+
else if (this.status >= 400 && this.status < 500){
55+
console.error("There is an error");
5456
};
5557
getByXhr.open('GET', 'https://xkcd.now.sh/?comic=614', true);
5658
getByXhr.send();

homework/Randomuser/Randomuser.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
const oRquest = new XMLHttpRequest();
1717
oRquest.responseType = 'json';
1818
oRquest.onreadystatechange = function() {
19-
if (this.readyState === 4 && this.status === 200) {
19+
if (this.readyState === XMLHttpRequest.DONE && this.status ===200) {
2020
console.log(oRquest.response);
2121
}
22+
else if (this.status >= 400 && this.status < 500){
23+
console.error("There is an error");
24+
}
2225
};
2326
oRquest.open('GET', 'https://www.randomuser.me/api', true);
2427
oRquest.send();

homework/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@
7474

7575
const ul = createAndAppend('ul', root);
7676
// .sort and .localeCompare used then .forEach
77-
repos.sort((a, b) => a.name.localeCompare(b.name)).forEach((repo) => renderRepoDetails(repo, ul));
77+
repos
78+
.sort((a, b) => a.name.localeCompare(b.name))
79+
.slice(0, 10)
80+
.forEach((repo) => renderRepoDetails(repo, ul));
7881
});
7982
}
8083

0 commit comments

Comments
 (0)