Random Words Generator doesn't work with >50 words

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


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

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


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

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

what do you mean that it doesn’t work? what happens?

I just tested you code locally with 6400 quotes.

It worked just like it did with only 3 quotes.

Your code, by itself, works just fine. If you can’t get it to work on your webpage, then that means there’s a problem with how you’re trying to connect your .html and .js files.

To list some of the possibilities,

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

Is your .js file named “javascript.js” verbatim? Is it located in the same folder with your .html file? If you answer no to any of these, then you have found your culprit.

If not,

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

Is the newQuote() function in your script file working properly?


<div id="quoteDisplay">
    <!--Quotes will display here -->

Are you selecting this properly in your script file, and setting its text content to the chosen quote?

Whenever you face a problem, it’s great to go step by step like this, eliminating all the possibilities one by one.