If c is even number then it means digit extracted is at even place
if ( c % 2 == 0 ) sumEven += n % 10 ; else sumOdd += n % 10 ; n = Math . floor ( n / 10 ) ; c ++ ; } document . write ( " " + sumOdd ) ; document . write ( " " ) ; document . write ( " " + sumEven ) ; } let n = 457892 ;