Find sum of the series 1 | javascript program to find sum of first n terms of the given series ; when n is odd ; when n is not odd ; no . of terms to find the sum
function calculateSum ( n ) { if ( n % 2 == 1 ) return ( n + 1 ) / 2 ; return - n / 2 ; } var n = 8 ; document . write ( calculateSum ( n ) ) ;