Check if product of digits of a number at even and odd places is equal | Javascript implementation of the approach ; To store the respective product ; Converting integer to String ; Traversing the String ; Driver code
function getResult ( n ) { let proOdd = 1 ; let proEven = 1 ; let num = n . toString ( ) ; for ( let i = 0 ; i < num . length ; i ++ ) if ( i % 2 == 0 ) proOdd = proOdd * ( num [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; else proEven = proEven * ( num [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; if ( proOdd == proEven ) document . write ( " " ) ; else document . write ( " " ) ; } let n = 4324 ; getResult ( n ) ;