Javascript 尝试合并随机数
我试图在函数中传递它们并将其放入数组中,但结果是错误的。我想不出任何解决办法。结果是: 我想要的是这个样子Javascript 尝试合并随机数,javascript,jquery,Javascript,Jquery,我试图在函数中传递它们并将其放入数组中,但结果是错误的。我想不出任何解决办法。结果是: 我想要的是这个样子 [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
[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);
}
[4,4,4,4]
[4, 4, 4, 4]
[5, 5, 5, 5]
[4, 4, 4, 4]
$(“#machine1”).slotMachine({
活动:0,
延误:500,
随机化:函数(activeElementIndex){
var-activeElementIndex=Math.floor(Math.random()*(9-0+1))+0;
//log(activeElementIndex);
调用我(activeElementIndex);
返回activeElementIndex;
}
}).洗牌(5);
$(“#machine2”).slotMachine({
活动:0,
延误:700,
方向:“向下”,
随机化:函数(activeElementIndex){
var-activeElementIndex=Math.floor(Math.random()*(9-0+1))+0;
//log(activeElementIndex);
调用我(activeElementIndex);
返回activeElementIndex;
}
}).洗牌(5);
$(“#machine3”).slotMachine({
活动:0,
延误:900,
随机化:函数(activeElementIndex){
var-activeElementIndex=Math.floor(Math.random()*(9-0+1))+0;
//log(activeElementIndex);
调用我(activeElementIndex);
返回activeElementIndex;
}
}).洗牌(5);
$(“#machine4”).slotMachine({
活动:0,
延误:1100,
方向:“向下”,
随机化:函数(activeElementIndex){
var-activeElementIndex=Math.floor(Math.random()*(9-0+1))+0;
//log(activeElementIndex);
调用我(activeElementIndex);
返回activeElementIndex;
}
}).洗牌(5);
函数调用(等待){
var nice=[];
对于(变量i=0;i<4;i++){
等一下;
}
console.log(nice);
}
在任何函数和开关之外定义nice[]
数组:
call_me(activeElementIndex) > nice.push(activeElementIndex)
谢谢,它解决了我的问题!为你竖起大拇指!