Lucas Numbers | Iterative function ; declaring base values for positions 0 and 1 ; generating number ; Driver Code
function lucas ( n ) { let a = 2 , b = 1 , c , i ; if ( n == 0 ) return a ; for ( i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return b ; } let n = 9 ; document . write ( lucas ( n ) ) ;