我正在尝试获取一个不同于先前math.random值的值,因此当这些数字写入文档时,如果它们相同,则math.random将生成另一个不相同的数字。它可能需要继续生成,直到值不同为止。
function rands() {
return Math.floor(Math.random() * 20) + 1;
}
var rand1 = rands();
var rand2 = rands();
var rand3 = rands();
var rand4 = rands();
var rand = [];
function myFunction() {
document.getElementById("random1").value = rand1;
document.getElementById("random2").value = rand2;
document.getElementById("random3").value = rand3;
document.getElementById("random4").value = rand4;
if(rand1 == rand2 || rand1==rand3 || rand1==rand4 || rand2 == rand3 || rand2 == rand4 || rand3==rand4){
console.log("Duplicate");
}
}
myFunction()https://stackoverflow.com/questions/51913277
复制相似问题