+ 5

[DUPLICATE] How to get random results in js?

please post an example for that.

11th Jun 2018, 8:20 AM
keev23i
keev23i - avatar
6 Answers
+ 5
Use Math.random() to produce random numbers between 0 and 1 that can be used as values to your program to achieve random results. Here's a sample code. Edit: the code now shows random values of an array. https://code.sololearn.com/WGzpyAXmUxo3/?ref=app
11th Jun 2018, 8:44 AM
Jonathan Pizarra
Jonathan Pizarra - avatar
11th Jun 2018, 9:13 AM
Dev
Dev - avatar
+ 7
You can generate a random number by Math.random function in js. For getting a whole number between two number without decimal places is to Math.floor(Math.random()*10)+1. This generates a random number between 1 to 10. See my code. https://code.sololearn.com/WtdDN6s147SU/#html
11th Jun 2018, 8:45 AM
Akash Pal
Akash Pal - avatar
+ 6
Jonathan Pizarra Akash Pal not that . how to get random text from an array? for example, if we had two words such as HTML and js .it must display a random one.
11th Jun 2018, 8:47 AM
keev23i
keev23i - avatar
11th Jun 2018, 8:53 AM
keev23i
keev23i - avatar
+ 3
Gangineni Goutham Choudary check my code again. I have edited it.
11th Jun 2018, 8:53 AM
Jonathan Pizarra
Jonathan Pizarra - avatar