I have an array called answers, and it's length is 20. So Math.floor(Math.random() * answers.length);
is equivalent to Math.floor(Math.random() * 20);
I would like to randomly select any ONE of those 20 entries in the array, which means I'd like 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 to be the possible numbers to be selected; so every entry can be selected. Would that mean I should use Math.floor(Math.random() * answers.length) + 1;
?
samedi 22 juillet 2017
How might I use answers.length to select any one entry from an array?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire