Finding sum of digits of a number until sum becomes single digit | Javascript program to find sum of digits of a number until sum becomes single digit . ; Function to get sum of digits ; function call
let n = 1234 ; function getSum ( n ) { let sum = 0 ; while ( n > 0 sum > 9 ) { if ( n == 0 ) { n = sum ; sum = 0 ; } sum = sum + n % 10 ; n = Math . floor ( n / 10 ) ; } return sum ; } document . write ( getSum ( n ) ) ;