Skip to content

API issues #1

Description

@Soala7

I wrote a javascript code that connects my user on my website to generate random quotes based on what they would like but it's not working here is the code

Script. js
async function getQuote() {
const category = document.getElementById("category").textContent || "success";
const quoteText = document.getElementById("quote");
const quoteAuthor = document.getElementById("author");

quoteText.textContent = "Loading...";
quoteAuthor.textContent = "";

try {
const res = await fetch('https://quote-generator-api-six.vercel.app/' + category);
const data = await res.json();

quoteText.textContent = `"${data.content}"`;
quoteAuthor.textContent = "– " + data.author;

} catch (err) {
quoteText.textContent = "Could not fetch quote. Please try again.";
quoteAuthor.textContent = "";
console.error(err);
}
}

// Load first quote
getQuote();

// Update every 10 seconds
setInterval(getQuote, 10000);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions