-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdog.js
34 lines (29 loc) · 989 Bytes
/
dog.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
const DOG_URL = "https://dog.ceo/api/breeds/image/random";
const promise = fetch(DOG_URL);
const doggos = document.querySelector(".doggos");
promise
.then(function(response) {
const processingPromise = response.json();
return processingPromise;
})
.then(function(processedResponse) {
const img = document.createElement("img");
img.src = processedResponse.message;
img.alt = "Cute doggo";
doggos.appendChild(img);
});
function addNewDoggo() {
const promise = fetch(DOG_URL);
promise
.then(function(response) {
const processingPromise = response.json();
return processingPromise;
})
.then(function(processedResponse) {
const img = document.createElement("img");
img.src = processedResponse.message;
img.alt = "Cute doggo";
doggos.appendChild(img);
});
}
document.querySelector(".add-doggo").addEventListener("click", addNewDoggo);