Stefan Đorđević
Stefan Đorđević

Reputation: 595

Random generate custom text with url in JS

I found this javascript random text generator from list

var quotes=new Array();
quotes[0] = "text1";
quotes[1] = "Text2";
quotes[2] = "text3";
quotes[3] = "text4";

var q = quotes.length;
var whichquote=Math.round(Math.random()*(q-1));
function showquote(){document.write(quotes[whichquote]);}
showquote();

And html:

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

So, it works perfectly, BUT... I want that every text that is generated have specified url, like <a href="#">

Thanks!

Upvotes: 2

Views: 509

Answers (1)

Igor
Igor

Reputation: 2919

As far as I could get what you need, this might do the job:

function showquote(){document.write('<a href="#">' + quotes[whichquote] + '</a>');}

Upvotes: 1

Related Questions