【发布时间】:2020-08-15 14:55:17
【问题描述】:
您好,我有一个随机报价生成器。我的问题是如何在数组中随机生成一个项目而不连续两次获得相同的项目?
我将在下面发布我的项目,我想让它尽可能简单,谢谢你的帮助。
这是我所有的 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;
}
这是我所有的 html 编码:
<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>.
这是我的 Javascript 代码,我不确定要添加什么以及在哪里添加?:
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
【问题讨论】:
-
添加你已经完成的代码..在这里可以解决你的作业。
-
这能回答你的问题吗? Create an array with random values
标签: javascript html css