不重复的报价生成器不起作用

您好,我想使用 RandomQuoteGenerator 脚本,我在 stackoverflow 上找到了一个脚本,但我希望它不重复引号,我在这里找到了一个解决方案,但它对我不起作用。单击按钮时出现未定义的错误。上面链接中提供的原始脚本工作正常,但如果我更改上面链接中提到的函数,我将收到未定义的消息而不是引号。

我的 Generator.js


var quotes = [

//success quotes

  {

    quote: "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success.",

    source: "James Cameron",

    tag: "success"

  },

  {

    quote: "The Way Get Started Is To Quit Talking And Begin Doing",

    source: "Walt Disney",

    tag: "success"

  },

  {

    quote: "Don’t Let Yesterday Take Up Too Much Of Today.",

    source: "Will Rogers",

    tag: "success"

  },

  {

    quote: "We Generate Fears While We Sit. We Overcome Them By Action",

    source: "Dr. Henry Link",

    tag: "success"

  },


//health quotes

  {

    quote: "Early to bed and early to rise, makes a man healthy wealthy and wise.",

    source: "Benjamin Franklin",

    tag: "health"

  },

  {

    quote: "Let food be thy medicine and medicine be thy food.",

    source: "Hippocrates",

    tag: "health"

  },

  {

    quote: "If you can’t pronounce it, don’t eat it.",

    source: "Common Sense",

    tag: "health"

  },

  {

    quote: "Health is like money, we never have a true idea of its value until we lose it.",

    source: "Josh Billings",

    tag: "health"

  },


//spirituality quotes

  {

    quote: "Life is really simple, but men insist on making it complicated.",

    source: "Confucius",

    tag: "spirituality"

  },

  {

    quote: "My religion is very simple. My religion is kindness.",

    source: "Dalai Lama",

    tag: "spirituality"

  },

  {

    quote: "Knowing others is wisdom; knowing the self is enlightenment.",

    source: "Tao Te Ching",

    tag: "spirituality"

  },

  {

    quote: "When there is love in your heart, everything outside of you also becomes lovable.",

    source: "Veeresh",

    tag: "spirituality"

  }

];


桃花长相依
浏览 87回答 1
1回答

POPMUISE

您的函数getRandomQuote()返回一个数组,因此为了访问该对象,您需要访问该数组的第一个元素。像这样...getQuote[0].quote
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript