THAT SENTENCE IS WRONG. "It shows three random elements from the array at three position in the HTML page."
Because you can get same elements from the array. There is a big chance to get same number from 0 - 9 .
Hi,
You have some useful information on your site.
On your code above, I was wondering:
var firstRandomNumber = (Math.round((Math.random()*8)+1))
Since 1 is always added to the Math.random()*8 return value, it doesn't seem that you would ever get 0.
I used your code with a slight variation. I was thinking something like:
var firstRandomNumber = (Math.round(Math.random()*(arrName.length - 1))
might get the full range of the array.
Best,
Curtis
ErrorGuest June 12, 2011 at 9:48 PM
It will never pick item 0 of the array(Amit). Use var randomnumber=Math.floor(Math.random()*10) instead.
WRONGStudent April 12, 2012 at 9:16 PM
THAT SENTENCE IS WRONG. "It shows three random elements from the array at three position in the HTML page." Because you can get same elements from the array. There is a big chance to get same number from 0 - 9 .
JavaScript array get elements at randomCurtis May 5, 2012 at 11:00 PM
Hi, You have some useful information on your site. On your code above, I was wondering: var firstRandomNumber = (Math.round((Math.random()*8)+1)) Since 1 is always added to the Math.random()*8 return value, it doesn't seem that you would ever get 0. I used your code with a slight variation. I was thinking something like: var firstRandomNumber = (Math.round(Math.random()*(arrName.length - 1)) might get the full range of the array. Best, Curtis
Post your Comment