Sum of an Array, javascript -
ok i'm working on lab assignment school in have generate 10 random numbers. code have far that. second part have have display sum of numbers using document.write or other display method, , pretty stumped.
<html> <head> <title> lab 5 </title> </head> <body> <script type="text/javascript"> var numbers = new array(10); var sum = 0; var i; </script> <script type="text/javascript"> (var = 0; <10; i++) { document.write("numbers[" + + "]: " + math.floor(math.random() *100)+ "<br/>"); } </script> </body> </html>
thanks help!
you need edit things bit. need create random_number
variable , assign random figure, can output value , add sum.
hope helps!
<html> <head> <title> lab 5 </title> </head> <body> <script type="text/javascript"> var numbers = new array(10); var sum = 0; var i; </script> <script type="text/javascript"> var total = 0; (var = 0; <10; i++) { var random_number = math.floor(math.random() *100); document.write("numbers[" + + "]: " + random_number + "<br/>"); sum += random_number; } document.write("total: " + sum); </script> </body> </html>
Comments
Post a Comment