Sum of the products of same placed digits of two numbers | Function to find the sum of the products of their corresponding digits ; Loop until one of the numbers have no digits remaining ; Driver Code
function sumOfProductOfDigits ( n1 , n2 ) { let sum = 0 ; while ( n1 > 0 && n2 > 0 ) { sum += ( ( n1 % 10 ) * ( n2 % 10 ) ) ; n1 = Math . floor ( n1 / 10 ) ; n2 = Math . floor ( n2 / 10 ) ; } return sum ; } let n1 = 25 ; let n2 = 1548 ; document . write ( sumOfProductOfDigits ( n1 , n2 ) ) ;