forked from Return-Ready-PT-Mon-Wed/AJAX-Activity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
27 lines (25 loc) · 908 Bytes
/
app.js
File metadata and controls
27 lines (25 loc) · 908 Bytes
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
const ApiHttps = "https://dog.ceo/api/breeds/image/random/3";
const btn = document.querySelector(".btn");
const randomPupElement = document.querySelector(".card-group");
async function getRandomPup() {
randomPupElement.innerHTML = "";
const response = await fetch(ApiHttps); // resolve promise
const json = await response.json(); // parse into json
console.log(json.message);
//
// foreach iterates over the message array
json.message.forEach((bitcoinPupImage) => {
// create template literal for Dom Elements
randomPupElement.innerHTML += `
<div class="card">
<div class ="card-img-top">
<img src="${bitcoinPupImage}">
<div class="card-body">
</div>
</div>
</div>
`;
});
}
//button activates the function
btn.addEventListener("click", getRandomPup);