Trying to add a button to this script so it will generate the numbers on click. Also I dont want the numbers to ever repeat in the same order. Im doing this inside of sqaurespace as well.
We are trying to come up with a way to give our users a unique ID for raffles from clicking this button.
Any help is really appreciated
<
h2 style="text-align: center;">Unique ID</h2>
<p id="array_number" style="font-size: 25px; text-align: center;"></p>
<input id="Generate" type="button" value="Generate" onclick="();" />
<javascript>
<script>
var min = 1;
var max = 90;
//Number of numbers to extract
var stop = 6;
var numbers = [];
for (let i = 0; i < stop; i++) {
var n = Math.floor(Math.random() * max) + min;
var check = numbers.includes(n);
if(check === false) {
numbers.push(n);
} else {
while(check === true){
n = Math.floor(Math.random() * max) + min;
check = numbers.includes(n);
if(check === false){
numbers.push(n);
}
}
}
}
sort();
//Sort the array in ascending order
function sort() {
numbers.sort(function(a, b){return a-b});
document.getElementById("array_number").innerHTML = numbers.join(" - ");
}
</script>
</javascript>
Aucun commentaire:
Enregistrer un commentaire