Check whether product of digits at even places of a number is divisible by K | Function checks whether product of digits at even places is divisible by K ; Converting integer to string ; Traversing the string ; Driver code
function productDivisible ( n , k ) { var product = 1 ; var num = n . toString ( ) for ( let i = 0 ; i < num . length ; i ++ ) { if ( i % 2 == 0 ) { product = product * Number ( num [ i ] ) } } if ( product % k == 0 ) { return true } else { return false ; } } var n = 321922 var k = 3 if ( productDivisible ( n , k ) ) { document . write ( " " ) } else { document . write ( " " ) }