Home > database >  I am trying to log the author name and the quote from the JSON file, but the code is not working?
I am trying to log the author name and the quote from the JSON file, but the code is not working?

Time:11-02

I am trying to log into the console the quoteAuthor and quoteText from the data array object, but it's not working Can someone help me, why this code is not working?

const showJokes = () => {

  return fetch("https://quote-garden.herokuapp.com/api/v3/quotes")
    .then(response => response.json())
    .then(data => {
      data.data.forEach(message => {
        let author = message.quoteAuthor;
        let quote = message.quoteText;
        return showAllJokes(`${author} - ${quote}`)
      })
    });

}

function showAllJokes(fullName) {
  console.log(fullName);
}

json file

CodePudding user response:

I can only see functions declaration in your provided snippet, perhaps you did forgot to call your showJokes function?

const showJokes = () => {
  return fetch("https://quote-garden.herokuapp.com/api/v3/quotes")
    .then(response => response.json())
    .then(data => {
      data.data.forEach(message => {
        let author = message.quoteAuthor;
        let quote = message.quoteText;
        return showAllJokes(`${author} - ${quote}`)
      })
    });

}

function showAllJokes(fullName) {
  console.log(fullName);
}

showJokes() // <- Add this line 
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related