Program to check if a number is divisible by sum of its digits | JavaScript implementation of above approach ; Converting integer to String ; Initialising sum to 0 ; Traversing through the String ; Converting character to int ; Comparing number and sum ; Driver Code ; Passing this number to get result function
function getResult ( n ) { let st = ( n ) . toString ( ) ; let sum = 0 ; for ( let i of st . split ( " " ) ) { sum = sum + parseInt ( i ) ; } if ( n % sum == 0 ) return " " ; else return " " ; } let n = 123 ; document . write ( getResult ( n ) + " " ) ;