title: Display Random Item From Array On Button Click, NO TWO IN A ROW
body: <p>I have a button that displays a quote and author from an array. I need the button to display a random quote/author each time the button is clicked. No two same quotes/authors in a row!</p>
  
  <pre><code>window.onload = function()
  {
      //assign var to quoteText id contents
      var quoteSpan = document.getElementById("quoteText");
  
      //assign var to authorText id contents
      var authorSpan = document.getElementById("authorText");
  
      //assign var to submitButton contents   
      var submitButton = document.getElementById('submit');
  
      var quotes = [
          {'text': '"Whatever you are, be a good one."', 'author': '-Abraham Lincoln'}, 
          {'text': '"It has been my philosophy of life that difficulties vanish when faced boldly."', 'author': '-Isaac Asimov'}, 
          {'text': '"Enjoy life. There’s plenty of time to be dead."', 'author': '-Anonymous'}, 
          {'text': '"Every moment is a fresh beginning."', 'author': '-T.S. Eliot'}, 
          {'text': '"One day your life will flash before your eyes. Make sure it is worth watching."', 'author': '-Anonymous'}
      ];  
  
      var oldQuoteIndex = -1; //unfound item in array is -1
  
      //function determining random quote
      function nextQuote() {
  
          do { 
              var newQuoteIndex = Math.floor(Math.random() * quotes.length); //picks random quote index from quotes array
  
          }   while (newQuoteIndex == oldQuoteIndex); //while index of newly chosen quote is the same as the index of old quote
  
          quoteSpan.innerHTML = quotes[newQuoteIndex].text; //make HTML's quoteText random quote
          authorSpan.innerHTML = quotes[newQuoteIndex].author; //make HTML's authorText random author
  
          var oldQuoteIndex = newQuoteIndex; //make old index same as new index, so that next time it runs, the WHILE aspect causes DO aspect to randomize
      }
  
      //when button is clicked, quotation function starts
      submitButton.onclick = nextQuote;
  
  }
  </code></pre>