Find Nth term of the series where each term differs by 6 and 2 alternately | Function to find Nth term ; Iterate from 1 till Nth term ; Check if i is even and then add 6 ; Else add 2 ; Print ans ; Driver Code
function findNthTerm ( N ) { let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { ans = ans + 6 ; } else { ans = ans + 2 ; } } document . write ( ans + " " ) ; } let N = 3 ; findNthTerm ( N ) ;