lundi 7 octobre 2019

Get random number from array, no repeat (with Timer) :)

Hi and Thank you for reading this post.

I'm trying to create an automatic Bingo call-out-loud number game but I keep getting undefined on the console log. Any ideas?

I have an array, this items need to be call randomly with no repeat, and when finish stop and say something like "the end" or "finish".

Thank you so much!!!!

  var nums = ["one","two","three","four","five","six","seven","eight","nine","ten"],
ranNums = [],
i = nums.length,
j = 0;

      setInterval(getNum,2000);

      function getNum(){
       j = Math.floor(Math.random() * (i+1));
ranNums.push(nums[j]);
nums.splice(j,1);
          console.log(ranNums[ranNums.length-1]);
          }



Aucun commentaire:

Enregistrer un commentaire