Check whether a given number is an ugly number or not | Function to check if a number is an ugly number or not ; Base Cases ; Condition to check if the number is divided by 2 , 3 , or 5 ; Driver Code
function isUgly ( n ) { if ( n == 1 ) return 1 ; if ( n <= 0 ) return 0 ; if ( n % 2 == 0 ) { return ( isUgly ( n / 2 ) ) ; } if ( n % 3 == 0 ) { return ( isUgly ( n / 3 ) ) ; } if ( n % 5 == 0 ) { return ( isUgly ( n / 5 ) ) ; } return 0 ; } let no = isUgly ( 14 ) ; if ( no == 1 ) document . write ( " " ) ; else document . write ( " " ) ;