0

我正在尝试洗牌 6 个 T 和 6 个 A 并循环直到到达数组的末尾。但是,当我循环播放时,我不断显示不均匀数量的 T 和 A。我是 javascript 新手,不确定问题是否与随机播放或循环有关。

//function to shuffle word array
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// remaining elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
    return array;
}
var wordt= ["T", "A","T", "A","T", "A","T", "A","T", "A","T", "A"]; //Your words
shuffle(wordt)
var i = 0;
    var currentWordt = 0;
    //pull T/A
    while (12 !==currentWordt) {
    var my_wordt =  wordt[i];
    var nb = jQuery('#NextButton');
    nb.val(my_wordt);
    nb.attr('title', my_wordt);
    i +=1
    currentWordt += 1
    }
4

0 回答 0