Sum of first n natural numbers | Function to find the sum of series ; Driver code
function seriesSum ( n ) { var sum = 0 ; for ( i = 1 ; i <= n ; i ++ ) sum += i * ( ( i + 1 ) / 2 ) ; return sum ; } var n = 4 ; document . write ( seriesSum ( n ) ) ;