Random quote page reload javascript

278 views Asked by At

I am attempting to have the page reload with a different message in each part. I thought I had it perfectly but cannot figure out why it isn't showing exactly.

here is the code

Html

<div id="words"></div>

And here is the Javascript

var words = new Array();
words[0] = " loves you";
words[1] = "Would you like  to tuck you in?";
words[2] = " is here for you";
words[3] = "Did you know that  can be in 2 places at once?";
var random = Math.ceil (Math.random()*words.length) - 1;
$('words').set('html', words[random]);
1

There are 1 answers

1
Josh On

The section with "$" is using JQuery. It's possible that you have not included the JQuery library and it therefore does not understand the $ operator

Try putting this in the header of the page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>