Lottery numbers Javascript?
|
demo 22 Dec 2008 01:26pm I want to place a lottery on my web page. I want some Javascript code that will spit out a three digit number once every day. The digits can repeat. I do not want something where you push a button and it gives you a different number every time. I want the number to be the same for everyone that comes to the site. |
Answers
|
demo 22 Dec 2008 02:23pm <head> <script type="text/javascript"> function setLotto() { // get today's date var d = new Date(); // apply multiple transcendental transformations to // to combine date parts and convert result to string // - produces same value all day long var m = '' + Math.log( d.getFullYear() + Math.pow( d.getDate(), .5 ) + Math.pow( 12.345 + d.getMonth(), 1/3 ) ); // keep last three digits of transformed value var l = m.substring( m.length - 3 ); // write to page document.getElementById( 'lotto' ).innerHTML += l; } // do this onload for demo - if you want a button to // invoke it, set onclick="setLotto()" as the click // event handler window.onload = setLotto; </script> </head> <body> <div id="lotto">Today's Lottery Number is: </div> </body> </html> |
Related
Submit Answer
You must be logged in to post an answer. Please Login or Register.
Powered by phpMyAnswers.