2016-08-03 8 views
-1

Ich habe versucht, sie in einer Funktion übergeben und in das Array, aber die Ergebnisse. Ich kann mir keine Lösungen vorstellen. Dies ist das Ergebnis:Versuchen, die Randomize-Zahlen zu kombinieren

derjenige I ist wie dieser

[4,4,5,4] 

aussehen wollen, aber der Ausgang ist

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

Antwort

1

die nice[] Array außerhalb jeder Funktion definieren, und der Schalter:

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

Danke, es hat mein Problem behoben! Daumen hoch für dich! –

+0

danke Jungs Edvin Tenovimas und @Guy Altman –

Verwandte Themen