Skip to content

Commit 0f28c7a

Browse files
committed
update
1 parent 971cffe commit 0f28c7a

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

AJAX_Projects/1-chuck-norris-jokes/setup/app.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ const content = document.querySelector('.content');
33
const URL = 'https://api.chucknorris.io/jokes/random';
44
const img = document.querySelector('.container img');
55

6-
btn.addEventListener('click', () => {
7-
fetch(URL)
8-
// disini response di peroleh karena data.json
9-
.then((data) => data.json())
10-
.then((response) => showJoke(response));
6+
btn.addEventListener('click', async () => {
7+
// asyncawait
8+
try {
9+
const data = await fetch(URL);
10+
const response = await data.json();
11+
showJoke(response);
12+
} catch (error) {
13+
console.log(error);
14+
}
1115
});
1216

1317
// function tuk filter only joke
1418
// sehingga tidak perlu membutuhkan JSON.parse
15-
// karena sudah ada data.json dan
19+
// karena sudah ada data.json dan
1620
// fungsi ini tinggal membuat obj destructingnya
1721
function showJoke({ value: joke }) {
1822
img.classList.add('shake-img');
@@ -23,12 +27,3 @@ function showJoke({ value: joke }) {
2327
img.classList.remove('shake-img');
2428
}, random);
2529
}
26-
27-
/* NOTE
28-
btn.addEventListener('click', () => {
29-
fetch(URL)
30-
// disini response di peroleh menghasilkan string json karena data.json
31-
.then((data) => data.json())
32-
.then((response) => console.log(response));
33-
});
34-
*/

AJAX_Projects/1-chuck-norris-jokes/setup/xhr-feth.js

Whitespace-only changes.

0 commit comments

Comments
 (0)