简体   繁体   中英

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 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM