Sum of the Series 1 + x / 1 + x ^ 2 / 2 + x ^ 3 / 3 + . . + x ^ n / n | JavaScript code to print the sum of the series ; Driver code
function sum ( x , n ) { let total = 1.0 ; let multi = x ; for ( let i = 1 ; i <= n ; i ++ ) { total = total + multi / i ; multi = multi * x ; } return total ; } let x = 2 ; let n = 5 ; document . write ( sum ( x , n ) . toFixed ( 2 ) ) ;