Skip to content

Instantly share code, notes, and snippets.

@kuznetsovandrey76
Created December 18, 2016 12:34
Show Gist options
  • Save kuznetsovandrey76/d81d8f758d0cdc4d7c1f21f07113fb0a to your computer and use it in GitHub Desktop.
Save kuznetsovandrey76/d81d8f758d0cdc4d7c1f21f07113fb0a to your computer and use it in GitHub Desktop.
without repeats
var text = document.getElementById('text'); // <div id="text"></div>
var quotes = '["1", "2", "3"]'; // any array (JSON or not JSON)
quotes = JSON.parse(quotes);
text.onclick = function foo() {
var random = parseInt(Math.random()*quotes.length);
var quote = quotes[random];
if(text.innerHTML == quote) {
return foo(); // start the function again
}
text.innerHTML = quote;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment