[英]I am trying to log the author name and the quote from the JSON file, but the code is not working?
我正在嘗試將數據數組對象中的 quoteAuthor 和 quoteText 登錄到控制台,但它不起作用有人可以幫助我,為什么此代碼不起作用?
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);
}
我只能在您提供的代碼段中看到functions
聲明,也許您確實忘記調用showJokes
函數?
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.