0

How do I input random numbers in array and then get their sum ?

27th May 2017, 9:17 PM
Manik Tafralian
Manik Tafralian - avatar
4 Respuestas
+ 2
for a sum of them : var sum, i; for(i=0, i<arr.length, i++){ sum+= arr[i]; }
27th May 2017, 9:35 PM
Amar
Amar - avatar
+ 1
try this: var arr = []; var rndNum = Math.round(Math.random()*x); arr[arr.length]=rndNum; **x is max number it can produce Now, you can put last 2 lines in some kind of loop to do it faster.
27th May 2017, 9:27 PM
Amar
Amar - avatar
+ 1
Thanks Amar
27th May 2017, 9:31 PM
Manik Tafralian
Manik Tafralian - avatar
+ 1
Thanks bunches
27th May 2017, 9:36 PM
Manik Tafralian
Manik Tafralian - avatar