-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (26 loc) · 988 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
const catResult = document.getElementById('cat_result');
const dogResult = document.getElementById('dog_result');
const catBtn = document.getElementById('cat_btn');
const dogBtn = document.getElementById('dog_btn');
catBtn.addEventListener('click', getRandomCat);
dogBtn.addEventListener('click', getRandomDog);
function getRandomCat() {
fetch('https://aws.random.cat/meow')
.then(response => response.json())
.then(data => {
// console.log(data);
catResult.innerHTML = `<img src=${data.file} alt="cat" download=${data.file} />`;
});
}
function getRandomDog() {
fetch('https://random.dog/woof.json')
.then(response => response.json())
.then(data => {
// console.log(data.url);
if (data.url.includes('.mp4')) {
getRandomDog();
} else {
dogResult.innerHTML = `<img class="w-full" src=${data.url} alt="dog" download/>`;
}
});
}