Check whether the given decoded string is divisible by 6 | Function to return the sum of the digits of n ; Function that return true if the decoded string is divisible by 6 ; To store the sum of the digits ; For each character , get the sum of the digits ; If the sum of digits is not divisible by 3 ; Get the last digit of the number formed ; If the last digit is not divisible by 2 ; Driver code
function sumDigits ( n ) { var sum = 0 ; while ( n > 0 ) { var digit = n % 10 ; sum += digit ; n = parseInt ( n / 10 ) ; } return sum ; } function isDivBySix ( str , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ) ; } if ( sum % 3 != 0 ) return false ; var lastDigit = ( ( str [ n - 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ) ) % 10 ; if ( lastDigit % 2 != 0 ) return false ; return true ; } var str = " " ; var n = str . length ; if ( isDivBySix ( str , n ) ) document . write ( " " ) ; else document . write ( " " ) ;