jeudi 10 novembre 2016

JavaScript Quotes of the day with assigned Authors

hey I spotted this the other day. It looks really good as it keeps locked to the specific day and doesn't change when you refresh, but I want to to add authors to the array. such as:

Quote // Author

with authors displaying on the next line, as well as randomizing the quote order.

Any tips?

<script type="text/JavaScript"> 
var quote = new Array(); 
quote[0] = 'quote 1 Lorem ipsum dolor sit amet, consectetuer adipiscing     elit.'; 
quote[1] = 'quote 2 Nullam commodo venenatis elit. In aliquam.'; 
quote[2] = 'quote 3 Sed vitae risus ac urna pharetra tristique.'; 
quote[3] = 'quote 4 Maecenas id mi quis nisl porta sodales.'; 
quote[4] = 'quote 5 Fusce lorem velit, tempor sit amet, luctus nec, suscipit at, velit'; 
quote[5] = 'quote 6 Ut pellentesque mauris non justo. In varius.'; 
quote[6] = 'quote 7 Phasellus non urna dignissim nisl mollis consectetuer.'; 
var qlen = quote.length; 
var firstDate = new Date(2005,0,1);//start date (yyyy,m,d) - m=0=January, m=1=February 
var today = new Date();//today 
var dif = Math.floor((today-firstDate)/1000/60/60/24);//difference in days 
while(dif>=qlen){//calculate the index of the quote of the day 
dif=dif-qlen;//restart the array index if the difference is greater that the array's length 
} 
var todayQuote = quote[dif];//the quote of the day 
onload = function(){document.getElementById('q').firstChild.data = todayQuote} 
</script> 
</head> 
<body> 
<div id='q'>&nbsp;</div> 
</body> 
</html> 

many thanks.




Aucun commentaire:

Enregistrer un commentaire