Example of random number (1 - 100000000)


Example of random number (1 - 100000000) with random number of digits






How do you add the values of a random amount of elements in jQuery?


Random array of numbers separated by a comma.






For the random amounts to add up, I use the following function:
1.  function randomArrayResult()
2.  {
3. 	   var arr = $("#arrayvalues").val().split(",");
4.     var total = 0;
5.     $.each(arr,function() 
6. 	   {
7. 		 total += parseInt(this);
8. 	   });
9.     $("#randomArrayResult").val(total);
10. }
Line 3 splits the comma-delimited string into an array of numeric values. Line 5 creates a loop to examine each numeric item in the array of numeric values. Line 7 converts the current item in the array "this" into a number and adds the number to the current value of the variable "total". Line 9 displays the result by setting the label "randomArrayResult" to the result.