-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom1.js
49 lines (34 loc) · 1.02 KB
/
random1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Created by Miss_Jessica_Lynne on 6/23/15.
*/
var lotteryArray = [];
var lotteryNumbers = [];
var chosenNumbers = [];
for (var i=1; i<50; i++) {
lotteryArray.push(i);
}
console.log (lotteryArray);
function pickNumbers () {
// Generate a random number from the array
var random = Math.floor(Math.random() * lotteryArray.length);
var number = lotteryArray[random];
console.log(number);
// Add the number to the array
lotteryArray.splice(random, 1);
lotteryNumbers.push(number);
//print the array out
var chosenNumbers = lotteryNumbers.join(",");
$("#list").append('<li>' + number + '</li>');
}
function start() {
timer = setInterval(function() {
pickNumbers();
if(lotteryNumbers.length > 5) {
window.clearInterval(timer);
var sortNumbers = lotteryNumbers.sort(function(a,b){return a-b;});
$('#list').find('li').each(function (index) {
$(this).text(sortNumbers[index]);
});
}
}, 1000);
}