Hi. I am an under-graduate currently studying Open Source (Linux) vs Closed
Source and Collaboration within the IT Community. I am fairly new to
Javascript and I have written a "Lottery Program" which essentially picks 6
numbers at random and puts them in sequence.
Would anyone would be interested in modifying the code below to
a). Check for bugs
b). Make the program more efficient
My idea is to see the response to this so as to make a comparison to
developers and the Open Source Movement.
Thanks
<HTML>
<HEAD>
<TITLE> Program_7.2.1 First Program
</TITLE>
<SCRIPT LANGUAGE = "JavaScript ">
/*************** *************** ***/
/* */
/* Lottery Program */
/* Author: Bill Marsden */
/* Date: 17/05/2004 */
/* */
/*************** *************** ***/
// Define Variables
var lott_one;
var lott_two;
var lott_three;
var lott_four;
var lott_five;
var lott_six;
var sort_numbers;
var another_go;
another_go = 'YES'
while (another_go == 'YES')
{
// Load the balls! Our adjudicator tonight is Bill Marsden !
lott_one = Math.floor(Math .random()*50+1) ;
lott_two = Math.floor(Math .random()*50+1) ;
// Main body of program testing for unique numbers
if (lott_two == lott_one)
{
lott_two = Math.floor(Math .random()*50+1)
}
;
lott_three = Math.floor(Math .random()*50+1) ;
if (lott_three == lott_two || lott_three == lott_one)
{
lott_three = Math.floor(Math .random()*50+1)
}
;
lott_four = Math.floor(Math .random()*50+1) ;
if (lott_four == lott_three || lott_four == lott_two || lott_four ==
lott_one)
{
lott_four = Math.floor(Math .random()*50+1)
}
;
lott_five = Math.floor(Math .random()*50+1) ;
if (lott_five == lott_four || lott_five == lott_three ||
lott_five == lott_two || lott_five == lott_one)
{
lott_five = Math.floor(Math .random()*50+1)
}
;
lott_six = Math.floor(Math .random()*50+1) ;
if (lott_six == lott_five || lott_six == lott_four ||
lott_six == lott_three || lott_six == lott_two || lott_six ==
lott_one)
{
lott_six = Math.floor(Math .random(1)*50+1 )
}
;
// We have our selection, lets sort them in ascending order
sort_numbers = [lott_one , lott_two , lott_three , lott_four , lott_five ,
lott_six]
function sortNumbers(a, b) { return a - b}
// Are you a lucky winner? Check the output!
document.write( 'And this weeks winning numbers are:' + '<BR>'
+ sort_numbers.so rt(sortNumbers) + '<BR>' + '<BR>' ) ;
another_go = window.prompt(' Another go? Enter YES/NO' , '') ;
}
;
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>