+ 2

How to get a random number in JavaScript

I want to make a math game involving random numbers but I don't know how to get random numbers. If that is not possible how to select from an array?

25th Sep 2019, 8:40 AM
Jacob Heath
Jacob Heath - avatar
1 Resposta
+ 5
--Random number: (between 0 and 1) Math.random() --Random number between 0 and what number you want: Math.floor(Math.random()*your number) --Random element from array: array[Math.floor(Math.random()*array.length)]
25th Sep 2019, 8:53 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar