views:

29

answers:

1

So I run this site: http://sometimesredsometimesblue.com

And more or less out of curiosity I was wondering if there was a more concise/elegant/interesting manner of how to code the... "functionality".

var redOrBlue=new Array("#0000FF", "#FF0000")
document.bgColor=redOrBlue[Math.floor(Math.random()*redOrBlue.length)]

There's nothing wrong with this of course. Really just curious.

+1  A: 
document.bgColor = (Math.random() < 0.5) ? '#0000FF' : '#FF0000';
LukeH