100-project-100-days-website/100_projects/76-fetch-api/main.js
2023-05-08 17:28:35 +03:00
Ask

28 lines
820 B
JavaScript

{3387836f646658d85fa5bd0778156616a4ad0363 true 820 main.js 0xc001fbbce0}

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