-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (22 loc) · 804 Bytes
/
app.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
35
const cat_btn = document.getElementById("cat_btn");
const dog_btn = document.getElementById("dog_btn");
const cat_result = document.getElementById("cat_result");
const dog_result = document.getElementById("dog_result");
cat_btn.addEventListener("click", getRandomCat);
dog_btn.addEventListener("click", getRandomDog);
// random macska
function getRandomCat() {
fetch("https://thatcopy.pw/catapi/rest/")
.then(res => res.json())
.then(data => {
cat_result.innerHTML = `<img src=${data.url} alt='cat' />`;
});
}
// random kutya
function getRandomDog() {
fetch("https://dog.ceo/api/breeds/image/random")
.then(res => res.json())
.then(data => {
dog_result.innerHTML = `<img src=${data.message} alt='dog' />`;
});
}