Divisibility by 12 for a large number | Javascript program to check if number is divisible by 12 ; If number greater then 3 ; Find last digit ; No is odd ; Find second last digit ; Find sum of all digits ; If number is less then or equal to 100 ; Driver code
function isDvisibleBy12 ( num ) { if ( num . length >= 3 ) { let d1 = num [ num . length - 1 ] . charCodeAt ( ) ; if ( d1 % 2 != 0 ) return false ; let d2 = num [ num . length - 2 ] . charCodeAt ( ) ; let sum = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) sum += num [ i ] . charCodeAt ( ) ; return ( ( sum % 3 == 0 ) && ( d2 * 10 + d1 ) % 4 == 0 ) ; } else { let number = parseInt ( num , 10 ) ; document . write ( number ) ; return ( number % 12 == 0 ) ; } } let num = " " ; if ( isDvisibleBy12 ( num ) ) document . write ( " " ) ; else document . write ( " " ) ;