Javascript 如何在数组中随机生成一个项,而不在一行中获取同一项两次?

Javascript 如何在数组中随机生成一个项,而不在一行中获取同一项两次?,javascript,html,css,Javascript,Html,Css,你好,我有一个随机报价生成器。我的问题是,如何在数组中随机生成一个项,而不在一行中获取同一项两次 下面我将张贴我的项目,我想保持它尽可能简单的项目谢谢你的任何帮助 以下是我所有的css编码: #heading { color: blue; } #containing-square { background-color: blue; height: 155px; width: 400px; text-align: center; margin: auto 500px;

你好,我有一个随机报价生成器。我的问题是,如何在数组中随机生成一个项,而不在一行中获取同一项两次

下面我将张贴我的项目,我想保持它尽可能简单的项目谢谢你的任何帮助

以下是我所有的css编码:

#heading {
  color: blue;
}

#containing-square {
  background-color: blue;
  height: 155px;
  width: 400px;
  text-align: center;
  margin: auto 500px;
  border-style: dashed;
}

#quoteDisplay {
  color: yellow;
  line-height: 40px;
  font-size: 20px;
  font-style: oblique;
  display: initial
}

#quote-button {
  margin: auto 660px;
  margin-bottom: 250px;

}

  <div id="containing-square">
    <div id="quoteDisplay">
      Step Into the Mind of Greatness
    </div>
  </div>
  <button id="quote-button" onclick="quote_machine()"> New Quote</button>.  

var seenquote = false
    var quotes = [
      "Men are not the creature of circumstances, circumstances are the creatures of men. </br> -Benjamin Desraili ",
      "The secret to life is learning how to use pain and pleasure,if you do that, you are in control in life, if you dont then life controls you. </br> -Anthony Robbins ",
      "Good judgement is the result of experience and experience the result of bad judgement. </br> -Mark Twain",
      "I'd rather die like a man than live like a coward. </br> -Tupac Shakur",
      "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment. </br> -Ralph W. Emmerson",
      "To be great is to be misunderstood. </br> -Ralph W. Emmerson",
      "Imagination is everything. It is the preview of life's coming attractions. </br> -Albert Einstein",
      "If you can't explain it simply, you don't understand it well enough. </br> -Albert Einstein",
      "Dude Suckin At Somthing Is The First Step At Being Sorta Good At Somthing. </br> -Jake (Adventure Time)",
      "The Way To Get Started Is To Quit Talking And Begin Doing.<br/> -Walt Disney",
      "Our Greatest Weakness Lies In Giving Up. The Most Certain Way To Succeed Is Always To Try Just One More Time. <br> - Thomas A. Edison",
      "Success Is Somthing you attract not somthing you persue, so instead of going after it you work on yourself. <br> -Jim rohn",
      "Income does not far exceed personal development <br> -",
      "If Someone Hands You A Million Dollars Best You Become A Millionaire Quickly So You Get To Keep The Money",
    ]

function quote_machine() {
      //makes random number 1-14 and stores it in randomnumber
      var randomNumber = Math.floor(Math.random() * (quotes.length));
      //targets quotedisplay and writes the array element located at that random number
      document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
    }
  </script>
</Body>

thank you for any help 

以下是我所有的html编码:

#heading {
  color: blue;
}

#containing-square {
  background-color: blue;
  height: 155px;
  width: 400px;
  text-align: center;
  margin: auto 500px;
  border-style: dashed;
}

#quoteDisplay {
  color: yellow;
  line-height: 40px;
  font-size: 20px;
  font-style: oblique;
  display: initial
}

#quote-button {
  margin: auto 660px;
  margin-bottom: 250px;

}

  <div id="containing-square">
    <div id="quoteDisplay">
      Step Into the Mind of Greatness
    </div>
  </div>
  <button id="quote-button" onclick="quote_machine()"> New Quote</button>.  

var seenquote = false
    var quotes = [
      "Men are not the creature of circumstances, circumstances are the creatures of men. </br> -Benjamin Desraili ",
      "The secret to life is learning how to use pain and pleasure,if you do that, you are in control in life, if you dont then life controls you. </br> -Anthony Robbins ",
      "Good judgement is the result of experience and experience the result of bad judgement. </br> -Mark Twain",
      "I'd rather die like a man than live like a coward. </br> -Tupac Shakur",
      "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment. </br> -Ralph W. Emmerson",
      "To be great is to be misunderstood. </br> -Ralph W. Emmerson",
      "Imagination is everything. It is the preview of life's coming attractions. </br> -Albert Einstein",
      "If you can't explain it simply, you don't understand it well enough. </br> -Albert Einstein",
      "Dude Suckin At Somthing Is The First Step At Being Sorta Good At Somthing. </br> -Jake (Adventure Time)",
      "The Way To Get Started Is To Quit Talking And Begin Doing.<br/> -Walt Disney",
      "Our Greatest Weakness Lies In Giving Up. The Most Certain Way To Succeed Is Always To Try Just One More Time. <br> - Thomas A. Edison",
      "Success Is Somthing you attract not somthing you persue, so instead of going after it you work on yourself. <br> -Jim rohn",
      "Income does not far exceed personal development <br> -",
      "If Someone Hands You A Million Dollars Best You Become A Millionaire Quickly So You Get To Keep The Money",
    ]

function quote_machine() {
      //makes random number 1-14 and stores it in randomnumber
      var randomNumber = Math.floor(Math.random() * (quotes.length));
      //targets quotedisplay and writes the array element located at that random number
      document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
    }
  </script>
</Body>

thank you for any help 

走进伟大的心灵
新报价。
这是我的Javascript代码,我不确定要添加什么以及在哪里添加?:

#heading {
  color: blue;
}

#containing-square {
  background-color: blue;
  height: 155px;
  width: 400px;
  text-align: center;
  margin: auto 500px;
  border-style: dashed;
}

#quoteDisplay {
  color: yellow;
  line-height: 40px;
  font-size: 20px;
  font-style: oblique;
  display: initial
}

#quote-button {
  margin: auto 660px;
  margin-bottom: 250px;

}

  <div id="containing-square">
    <div id="quoteDisplay">
      Step Into the Mind of Greatness
    </div>
  </div>
  <button id="quote-button" onclick="quote_machine()"> New Quote</button>.  

var seenquote = false
    var quotes = [
      "Men are not the creature of circumstances, circumstances are the creatures of men. </br> -Benjamin Desraili ",
      "The secret to life is learning how to use pain and pleasure,if you do that, you are in control in life, if you dont then life controls you. </br> -Anthony Robbins ",
      "Good judgement is the result of experience and experience the result of bad judgement. </br> -Mark Twain",
      "I'd rather die like a man than live like a coward. </br> -Tupac Shakur",
      "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment. </br> -Ralph W. Emmerson",
      "To be great is to be misunderstood. </br> -Ralph W. Emmerson",
      "Imagination is everything. It is the preview of life's coming attractions. </br> -Albert Einstein",
      "If you can't explain it simply, you don't understand it well enough. </br> -Albert Einstein",
      "Dude Suckin At Somthing Is The First Step At Being Sorta Good At Somthing. </br> -Jake (Adventure Time)",
      "The Way To Get Started Is To Quit Talking And Begin Doing.<br/> -Walt Disney",
      "Our Greatest Weakness Lies In Giving Up. The Most Certain Way To Succeed Is Always To Try Just One More Time. <br> - Thomas A. Edison",
      "Success Is Somthing you attract not somthing you persue, so instead of going after it you work on yourself. <br> -Jim rohn",
      "Income does not far exceed personal development <br> -",
      "If Someone Hands You A Million Dollars Best You Become A Millionaire Quickly So You Get To Keep The Money",
    ]

function quote_machine() {
      //makes random number 1-14 and stores it in randomnumber
      var randomNumber = Math.floor(Math.random() * (quotes.length));
      //targets quotedisplay and writes the array element located at that random number
      document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
    }
  </script>
</Body>

thank you for any help 
var seenkote=false
变量引号=[
“人不是环境的产物,环境是人的产物。
-本杰明·德斯利”, “生活的秘密在于学会如何利用痛苦和快乐,如果你这样做,你就能控制生活,如果你不这样做,那么生活就会控制你。
-安东尼·罗宾斯, “好的判断是经验的结果,经验是坏的判断的结果。
-马克吐温”, “我宁愿像个男人一样死去,也不愿像个懦夫一样活着。
-Tupac Shakur”, “在一个不断试图让你变得与众不同的世界里,做你自己是最大的成就。
-拉尔夫·W·埃默森”, “伟大就是被误解。
-拉尔夫·W·埃默森”, “想象力是一切。它是生命即将到来的吸引力的预告。
-阿尔伯特·爱因斯坦”, “如果你不能简单地解释它,你就不能很好地理解它。
-阿尔伯特·爱因斯坦”, “花花公子沉迷于某件事是成为某件事高手的第一步。
-杰克(冒险时代)”, “开始的方法是停止说话,开始行动。
-沃尔特·迪斯尼”, “我们最大的弱点在于放弃。成功最确定的方法就是再尝试一次。
-托马斯A.爱迪生”, “成功是你吸引的东西,而不是你追求的东西,所以与其追求它,不如自己努力。
-Jim rohn”, “收入不远超过个人发展”
-“, “如果有人给你一百万美元,你很快就会成为百万富翁,这样你就可以保留这笔钱”, ] 函数quote_machine(){ //生成随机数1-14并将其存储在随机数中 var randomNumber=Math.floor(Math.random()*(quotes.length)); //目标quotedisplay并写入位于该随机数处的数组元素 document.getElementById('quoteDisplay')。innerHTML=quotes[randomNumber]; } 谢谢你的帮助
这里有一个想法:

  • 深度复制
    quotes
  • 从深度副本中随机选取一个条目并显示它
  • 从深度副本中删除此条目(以防止在拾取所有其他条目之前拾取相同的条目)
  • 如果深度副本为空,请重新复制它


  • 添加您已经完成的代码。。我可以在这里解决你的家庭作业。这能回答你的问题吗?我试图在中实现这一点,但“let quotes=[…];”在第二个括号中出现错误]抱歉,我已经编写了2年的代码,感觉已经编写了两天了。@Patrowheels我没有键入您的报价以节省时间,我的意图是像您一样复制您的报价。难以置信!谢谢你@A.J.乌帕尔!如果我能对你有所帮助的话,我看到了你的A+网站,印象非常深刻。在平面设计的字眼下可能有一个小字体,上面写着“treams”而不是“dreams”。如果可以的话,我也只能说这句话,但你这么年轻就学到了很多,这给我留下了深刻的印象!非常感谢。当然:)谢谢你的检查!目前正在对其进行改进,并且一定会考虑到这一点。祝你好运。