Find first and last digits of a number | Find the first digit ; Remove last digit from number till only one digit is left ; return the first digit ; Find the last digit ; return the last digit ; Driver code
function firstDigit ( n ) { while ( n >= 10 ) n /= 10 ; return Math . floor ( n ) ; } function lastDigit ( n ) { return Math . floor ( n % 10 ) ; } let n = 98562 ; document . write ( firstDigit ( n ) + " " + lastDigit ( n ) ) ;