Find the n | Function to calculate nth number made of even digits only ; Variable to note how many such numbers have been found till now ; Bool variable to check if 1 , 3 , 5 , 7 , 9 is there or not ; Checking each digit of the number ; If 1 , 3 , 5 , 7 , 9 is found temp is changed to false ; temp is true it means that it does not have 1 , 3 , 5 , 7 , 9 ; If nth such number is found return it ; Driver Code
function findNthEvenDigitNumber ( n ) { let count = 0 ; for ( let i = 0 ; ; i ++ ) { let curr = i ; let isCurrEvenDigit = true ; while ( curr != 0 ) { if ( curr % 10 == 1 curr % 10 == 3 curr % 10 == 5 curr % 10 == 7 curr % 10 == 9 ) isCurrEvenDigit = false ; curr = Math . floor ( curr / 10 ) ; } if ( isCurrEvenDigit === true ) count ++ ; if ( count === n ) return i ; } } document . write ( findNthEvenDigitNumber ( 2 ) + " " ) ; document . write ( findNthEvenDigitNumber ( 10 ) + " " ) ;