Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alterando a BASE_URL para um novo serviço #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions javascript-assincrono/projeto-html/assets/js/scripts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
const BASE_URL = 'https://thatcopy.pw/catapi/rest/';
const BASE_URL = 'https://api.thecatapi.com/v1/images/search';
//'https://thatcopy.pw/catapi/rest';
const catBtn = document.getElementById('change-cat');

const getCats = async () => {
try {
const data = await fetch(BASE_URL);
const json = await data.json();
return json.webpurl;
} catch (e) {
console.log(e.message);
}
};
try{
const data = await fetch(BASE_URL);
const json = await data.json();

return json[0].url;


const loadImg = async () => {
const img = document.getElementsByTagName('img')[0];
img.src = await getCats();
} catch (e){
console.log(e.message);
}
};

loadImg();
const loadImg = async() => {
const catImg = document.getElementById('cat');
catImg.src = await getCats();
}

const btn = document.getElementById('change-cat');
btn.addEventListener('click', loadImg);
catBtn.addEventListener('click', loadImg);

loadImg();