random-quote-kethan
Version:
Generated random quotes.
22 lines (19 loc) • 582 B
JavaScript
const API_URL = "https://api.quotable.io/random";
async function getQuote() {
try {
const response = await fetch(API_URL);
const data = await response.json();
// Store the quote in a variable
const quoteString = `${data.content} - ${data.author}`;
return quoteString;
} catch (error) {
console.error("Error fetching quote:", error);
return "An error occurred. Please try again later.";
}
}
(async () => {
// Call the function and store the returned quote
const quote = await getQuote();
console.log(quote);
})();
module.exports = getQuote;