2016-08-03 62 views
-1

我试图将它们传递给一个函数,并放入数组中,但结果。我想不出任何解决办法。这是结果:试图结合随机数字

一个我想是这个样子

[4,4,5,4] 

但输出是

[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); 
    } 

回答

1

定义nice[]阵列的任何功能之外,切换:

call_me(activeElementIndex) > nice.push(activeElementIndex) 
+0

谢谢,它解决了我的问题!竖起大拇指给你! –

+0

谢谢你们Edvin Tenovimas和@Guy Altman –