Skip to content

Commit

Permalink
funcionando
Browse files Browse the repository at this point in the history
  • Loading branch information
Kell-C committed Oct 3, 2024
1 parent 213df11 commit 81fb4a9
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,37 @@ function complete() {

// Get Quote From API
async function getQuote() {
loading()
const proxyUrl = "http://cors-anywhere.herokuapp.com/";
const apiUrl =
"http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json";
try {
const response = await fetch(proxyUrl + apiUrl);
const data = await response.json();
// If Author is blank, add 'Unknown'
if (data.quoteAuthor === '') {
authorText.innerText = 'Unknown'
} else {
authorText.innerText = data.quoteAuthor;
}
// Reduce font size for long quotes
if (data.quoteText.length > 120) {
quoteText.classList.add('long-quote');
} else {
quoteText.classList.remove('long-quote');
quoteText.innerText = data.quoteText;
}
//Stop Louder, show the quote
complete();
} catch (error) {
getQuote()
loading();
// const proxyUrl = "http://cors-anywhere.herokuapp.com/";
try {
const response = await fetch("https://quotes-api-self.vercel.app/quote")
.then((response) => response.json())
.then((data) => {
// Handle the retrieved quote
if (data.author === "") {
authorText.innerText = "Unknown";
} else {
authorText.innerText = data.author;
}
// Reduce font size for long quotes
if (data.quote.length > 120) {
quoteText.classList.add("long-quote");
} else {
quoteText.classList.remove("long-quote");
quoteText.innerText = data.quote;
}
complete();
})
.catch((error) => {
// Handle any errors
console.error(error);
});
const data = await response.json();
// If Author is blank, add 'Unknown'

//Stop Louder, show the quote
complete();
} catch (error) {}
}


Expand Down

0 comments on commit 81fb4a9

Please sign in to comment.