jeudi 6 août 2020

Random Words Generator doesn't work with >50 words

I want to make a Random Words Generator using JavaScript and HTML. I wrote some code (below) - it works with ~50 words, but doesn't work with ~5000 words. What could be the problem?

Can't find the solution in Google

JavaScript:

var quotes = [
  "One", "Two", "Three"
]

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

HTML:

<!DOCTYPE html>
<html>
<<head>
  <title>Quote Gen</title>
</head>
<body>
  <h1>Simple Quote Generator</h1>
  <div id="quoteDisplay">
    <!--Quotes will display here -->
  </div>
  <button onclick="newQuote()">New Quote</button>

  <script src="javascript.js"></script>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire