I have 4 spans and I I want to fill thse spans with values that I already have on an array, the problem is I don't the first value gos in the first span what I want is that each value takes a random span
<span id="optiona"></span>
<span id="optionb"></span>
<span id="optionc"></span>
<span id="optiond"></span>
Each value on that array
var op1 = Math.floor(Math.random()*9563);
var op2 = Math.floor(Math.random()*1457);
var op3 = Math.floor(Math.random()*8547);
var answers = [op1,op2,op3,rightAnswer]
What I'm trying to do is
var answerDisplay = document.querySelectorAll(".answers span");
for(i=0;i<answers.length;i++){
answerDisplay[i].textContent = answers[rand()];
}
function rand(){
var randomN = Math.floor(Math.random()*answers.length);
return randomN;
}
My question is how to generate a random number witout repeating?
Aucun commentaire:
Enregistrer un commentaire