I made a simple quote slider that changes the sentence on the screen randomly upon each click, but I don't want it to show the same quote twice in a row. How can I exclude the current quote from the Math.random algorithm and make the slider show any other quote upon each click?
(I don't want each quote to be shown only once, I just want to prevent the slider to show the same one in a row)
HTML:
<div class="container" onclick="changequote()">
<div class="quote">Sentence 1</div>
<div class="quote">Sentence 2</div>
<div class="quote">Sentence 3</div>
</div>
<script>window.onload = changequote()</script>
JS:
function changequote() {
var random = Math.floor(Math.random() * $('.quote').length);
$('.quote').hide().eq(random).fadeTo(500, 1);
}
CSS:
.quote {
display: none;
}