dimanche 7 octobre 2018

How to generate non-recurring numbers from the range JavaScript

I have array with 10 items, I calls one random item using a random number from 1 to 10, what to use to make a random number from 1 to 10, which will not happen again, and when all 10 is used, the program stops randomly? code

const num = () => Math.floor(Math.random() * 10);
  const postWord = () => {
    randomWord = word.innerText = words[num()].PL;
  }

  postWord();

  submit.addEventListener("click", function() {
    postWord();
  });




Aucun commentaire:

Enregistrer un commentaire