forked from Pushkar111/JavaScript-ZeroToHero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi2.js
More file actions
26 lines (21 loc) · 870 Bytes
/
api2.js
File metadata and controls
26 lines (21 loc) · 870 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
// DOG Api Website ==> https://dog.ceo/dog-api/documentation/random
// Dog API ==> https://dog.ceo/api/breeds/image/random
let btn = document.getElementById("btn");
let result = document.getElementById("result");
btn.addEventListener("click", function () {
fetch("https://dog.ceo/api/breeds/image/random")
.then((response) => response.json())
.then((json) => {
console.log(json);
result.innerHTML = `<img src="${json.message}" alt="dog" class="randomImage"/>`;
});
});
let btn2 = document.getElementById("btn2");
btn2.addEventListener("click", function () {
fetch("https://dog.ceo/api/breeds/list/all")
.then((response) => response.json())
.then((json) => {
console.log(json);
result.innerHTML = JSON.stringify(json);
});
});