Find nth term of the series 5 2 13 41 | function to calculate nth term of the series ; to store the nth term of series ; if n is even number ; if n is odd number ; return nth term ; Driver code
function nthTermOfTheSeries ( n ) { let nthTerm ; if ( n % 2 == 0 ) nthTerm = Math . pow ( n - 1 , 2 ) + n ; else nthTerm = Math . pow ( n + 1 , 2 ) + n ; return nthTerm ; } let n ; n = 8 ; document . write ( nthTermOfTheSeries ( n ) + " " ) ; n = 12 ; document . write ( nthTermOfTheSeries ( n ) + " " ) ; n = 102 ; document . write ( nthTermOfTheSeries ( n ) + " " ) ; n = 999 ; document . write ( nthTermOfTheSeries ( n ) + " " ) ; n = 9999 ; document . write ( nthTermOfTheSeries ( n ) + " " ) ;