Find the sum of digits of a number at even and odd places | Function to find the sum of the odd and even positioned digits in a number ; To store the respective sum ; Converting integer to String ; Traversing the String ; Driver code
function getSum ( n ) { let sumOdd = 0 ; let sumEven = 0 ; let num = ( n ) . toString ( ) ; for ( let i = 0 ; i < num . length ; i ++ ) if ( i % 2 == 0 ) sumOdd = sumOdd + ( num [ i ] - ' ' ) ; else sumEven = sumEven + ( num [ i ] - ' ' ) ; document . write ( " " + sumOdd + " " ) ; document . write ( " " + sumEven + " " ) ; } let n = 457892 ; getSum ( n ) ;