I am trying to get a different value from the previous value of math.random, so when the numbers are written to the document, if they are the same then math.random will generate another number that is not the same. It may need to keep generating until the value is different.
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()
Aucun commentaire:
Enregistrer un commentaire