Need help with formula to add up a series

Hello, I’m trying to use the for loop below to add up a series of numbers, but all I get is the sum of the first number only. How can I accomplish this? How can I make the function recursive? Thanks.


		<script type = "text/javascript">


			function sum(){

				for(j=1; j<5; j++){

					x=0; //Initialize the horizontal displacement

					x += j; 

					return x;

				} 

			}//Function end

			alert(sum());


		</script>

Sponsor our Newsletter | Privacy Policy | Terms of Service