Nth term of a Custom Fibonacci series | Function to return the nth term of the required sequence ; Driver code
function nth_term ( a , b , n ) { var z = 0 ; if ( n % 6 == 1 ) z = a ; else if ( n % 6 == 2 ) z = b ; else if ( n % 6 == 3 ) z = b - a ; else if ( n % 6 == 4 ) z = - a ; else if ( n % 6 == 5 ) z = - b ; if ( n % 6 == 0 ) z = - ( b - a ) ; return z ; } var a = 10 , b = 17 , n = 3 ; document . write ( nth_term ( a , b , n ) ) ;