javascript - Check if the same number is randomized twice in a row -


i've made quote generator, times, because there few quotes, same quote shows twice in row. how check , avoid issue?

    randomnum = math.floor((math.random() * quotes.length));     randomquote = quotes[randomnum];     randomauthor = author[randomnum];      $("#quote").text(randomquote);     $("#author").text(randomauthor); }  $("#newquote").on('click', function() {     getquote(); }); 

full code.

you can check if new random quote equal previous quote , change if is.

replace randomnum = math.floor((math.random()*quotes.length)) with

while(randomquote === quotes[randomnum])         randomnum = math.floor((math.random()*quotes.length)); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -