Check if the sum of digits of number is divisible by all of its digits | Function that returns true if all the digits of n divide the sum of the digits of n ; Store a copy of the original number ; Find the sum of the digits of n ; Restore the original value ; Check if all the digits divide the calculated sum ; If current digit doesn 't  divide the sum ; Driver code
function isDivisible ( n ) { var temp = n ; var sum = 0 ; while ( n != 0 ) { var digit = parseInt ( n % 10 ) ; sum += digit ; n = parseInt ( n / 10 ) ; } n = temp ; while ( n != 0 ) { var digit = parseInt ( n % 10 ) ; if ( sum % digit != 0 ) return false ; n = parseInt ( n / 10 ) ; } return true ; } var n = 123 ; if ( isDivisible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;