[英]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.