简体   繁体   English

我试图从 JSON 文件中记录作者姓名和引用,但代码不起作用?

[英]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?我正在尝试将数据数组对象中的 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);
}

json file json文件

I can only see functions declaration in your provided snippet, perhaps you did forgot to call your showJokes function?我只能在您提供的代码段中看到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.

相关问题 我正在尝试使用javascript从json文件中提取中位数 - I am trying to pluck the median from a json file using javascript 我正在尝试从JSON文件中检索数据,但是我无法从特定属性中检索信息 - I am trying to retrieve data from a JSON file, but I am having trouble retrieving information from a specific property 我正在尝试从用户输入中获取一些数据到 JSON 文件中。我收到此消息 - I am trying to get some data from user input into a JSON file.I get this message 我试图将CORS正确地实现到我的JavaScript代码,并且工作了一段时间,我相信项目中缺少一些文件吗? - I am trying to implement CORS to my JavaScript code correctly, and it worked for a while, I believe I am missing some file from the project? 我正在尝试使用 axios 和本地 json 文件通过单击按钮来呈现随机数组元素。 我错过了什么? - I am trying to render a random array element from a button click using axios and a local json file. What am I missing? 我正在尝试使用 javascript 从 JSON 文件创建动态 html 选项 - I am trying to create dynamic html options from a JSON file using javascript 我的 script.js 文件中的新引用函数不会使作者姓名出现 - The new quote function in my script.js file does not make the author name appear 我正在尝试结合一个 JSON 文件在谷歌地图中创建标记 - I am trying to combine a JSON file to create markers in a google maps 为什么显示 function 未定义? 它确实在控制台中记录结果,我只是想列出名字 - Why is it showing that the function is not defined? It does log the results in console, I am just trying to list the first name 为什么console.log不能使用这个代码(我不是console.log(ging)无限) - why is console.log not working with this code(i am not console.log (ging) infinitely)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM