lundi 29 octobre 2018

Javascript Random Quote Generator - how to have quote appear as page first loads

I am building a random quote generator as my first javascript project. I am getting the quotes to work fine, but I would love to have them displaying as someone first visits the site, and not just when someone first clicks on the button.

Here is my code so far:

<div id="quoteDisplay">
  <!-- Quotes will display here -->
</div>
<!-- Center is added for button placement -->

  <button onclick="newQuote()">New Quote</button>

<script type="text/javascript" src="ron.js"></script>

and the javascript:

var quotes = ["quote 1", "quote 2", "quote 3",]

function newQuote() {
var randomNumber = Math.floor(Math.random() * (quotes.length));
document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];

}

any suggestions on what to add to make a quote display when a user first visits page?




Aucun commentaire:

Enregistrer un commentaire