100-project-100-days-website/100_projects/76-fetch-api/main.js

28 lines
820 B
JavaScript
Raw Normal View History

2023-05-08 17:28:35 +03:00
const cat_result = document.getElementById("cat_result");
const dog_result = document.getElementById("dog_result");
const cat_btn = document.getElementById("cat_btn");
const dog_btn = document.getElementById("dog_btn");
// cat_btn.addEventListener('click', getRandomCat);
dog_btn.addEventListener('click', getRandomDog);
// function getRandomCat(){
// fetch('https://random.dog/woof.json')
// .then(res => res.json())
// .then(data => {
// cat_result.innerHTML = `<img src="${data.url}"/>`
// })
// }
function getRandomDog(){
fetch('https://random.dog/woof.json')
.then(res => res.json())
.then(data => {
if(data.url.includes('.mp4')){
getRandomDog();
}
dog_result.innerHTML = `<img src="${data.url}"/>`
})
}
// Api
//https://github.com/public-apis/public-apis