Thomas Jericho Capuyan Thomas Jericho Capuyan - 4 months ago 23
Javascript Question

Trying to combine the randomize numbers

I tried to pass them in a function and put into the array but the results. I cannot think of any solutions. this is the result:

the one I want is look like this

[4,4,5,4]


but the output is

[4, 4, 4, 4]
[4, 4, 4, 4]
[5, 5, 5, 5]
[4, 4, 4, 4]






$("#machine1").slotMachine({
active : 0,
delay : 500,
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);

$("#machine2").slotMachine({
active : 0,
delay : 700,
direction: 'down',
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);

$("#machine3").slotMachine({
active : 0,
delay : 900,
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);

$("#machine4").slotMachine({
active : 0,
delay : 1100,
direction: 'down',
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);

function call_me(wait){
var nice = [];
for(var i = 0; i < 4; i++){
nice[i] = wait;
}
console.log(nice);
}

Answer

define the nice[] array outside any function and switch:

call_me(activeElementIndex) > nice.push(activeElementIndex)
Comments