+ 1

How to create a name picker using Math.floor(Math.random()*5), and when that happens, the random number will be used to pick a

a name, like #randomNumber pick from names, if the random number is 3 it will pick from the arrays.? sorry for my bad english😂

14th Jul 2018, 11:47 PM
MIkko Celestra Mercado
MIkko Celestra Mercado - avatar
1 ответ
+ 1
let choices = [/* Your array of names /*] // Random choice from 0 to 4 choices[Math.floor(5 * Math.random())]; // Random choice from 0 to n - 1 choices[Math.floor(n * Math.random())]; // Random choice from min to max choices[Math.floor(Math.random() * (max - min + 1)) + min;] You can declare a function to take choices as the argument.
15th Jul 2018, 12:59 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar