Hey everyone, this is my first post. I have finished a JavaScript tutorial on codeacademy.org’s site a few days ago. It took me a few months or so to complete it.

I figure now I have the basic understanding of Object Oriented Programing to dive into a small project I have been thinking of doing. Plus I learn best diving into whatever it is I am doing.

I am making a basic numbers generator for U.S. lottery called PowerBall. I have practiced working with jQuery before, but this I want to make from strait JavaScript (no libraries involved).

The generator is pretty simple really,5 white balls are picked at random ranging 01-59, as well as a red ‘poweball’ ranging 01-35.

I have gotten to the point where I have the basic HTML template and a button that runs a function on an onclick, but I can only get one result for the white ball #.

I have not looked at the PowerBall value yet as I figure it should be easy for one value and .push() the key to the assigned array.

I have only been working on the five numbers and I think of multiple ways it could be solved.I want to keep DRY (Don’t Reduplicate Yourself) and DIE (Duplication Is Evil) to a minimum. Unfortunately, I haven’t even got a repetitive block of js to work:

var whiteBall1 = Math.floor(Math.random() * 59 + 1);
var whiteBall2 = Math.floor(Math.random() * 59 + 1);
var whiteBall3 = Math.floor(Math.random() * 59 + 1);
var whiteBall4 = Math.floor(Math.random() * 59 + 1);
var whiteBall5 = Math.floor(Math.random() * 59 + 1);


and the print the variables.

I want to make an array of what the values should be. A for lop would then calculate for each key in the array:

var whiteBallArray = [i,i,i,i,i];
for (var i = 0; i < whiteBallArray.length; i++) {
var n = Math.floor(Math.random() * 59 + 1);
document.write(whiteBallArray[i]);


I did some further research and I found a blog about generator functions? I tried but no luck:

var whiteBallArray = [i,i,i,i,i];
var i = 0;
(function(whiteBallArray) {
return function() {
i = Math.floor(Math.random() * 59 + 1);
}
})(i);



I hope I gave enough information on here for the problem. Here is a pastebin link of the entire thing if you want to try and work it out.Find Powerball-js and Powerball-html..... So far I got the for loop to work, but the array shows the same value for all five keys...

I am using chome browser btw.

Thanks!