Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random Text From jQuery Array

I am trying to make an array of strings and then pluck a random string and place it in a div with class "quote". Below is my current code.

$(document).ready(function() {

    var quotes = new Array("foo", "bar", "baz", "chuck");
    var randno = Math.floor ( Math.random() * quotes.length );
    $('.quote').add(quotes[randno]);

});

What am I doing incorrectly?

Thanks

like image 896
conbask Avatar asked Dec 22 '22 00:12

conbask


1 Answers

$(document).ready(function() {
    var quotes = new Array("foo", "bar", "baz", "chuck"),
    randno = quotes[Math.floor( Math.random() * quotes.length )];
    $('.quote').text( randno );
});

try this

like image 136
Torrent Lee Avatar answered Jan 07 '23 12:01

Torrent Lee