I am new to programming and recently started learning JavaScript. I made a little program that randomly generate quotes. Currently the program takes quotes from an array by using Math.random() method. But some times randomly generated number is same as before and quote doesn't change.
What I want is that once a quote is generated it should not show again till user see 7 different quotes. How I can achieve this by using pure JavaScript? (See JSFiddle demo)
If you know multiple solutions please share all if it is possible.
Here is my code:
<body>
<h1>Random Quotes Generator</h1>
<p>Click <strong>Generate</strong> button to see quotes.</p>
<button>Generate!</button>
<script src="script.js"></script>
</body>
var heading = document.querySelector("h1");
var paragraph = document.querySelector("p");
var button = document.querySelector("button");
var randomQuotes = [
"I am 1st quote.",
"I am 2nd quote.",
"I am 3rd quote.",
"I am 4th quote.",
"I am 5th quote",
"I am 6th quote.",
"I am 7th quote.",
"I am 8th quote.",
"I am 9th quote.",
"I am 10th quote."
];
var generateQuote = function() {
paragraph.innerHTML = randomQuotes[Math.floor(Math.random() * 10)];
}
button.onclick = generateQuote;