Accumulate the charAt(*) for each n
As others have mentioned, you are attempting to find the digital sum of a given number. In JavaScript, you can do the following:

function digitalSum(number) {
  return (
    number
      .toString()
      .split('')
      .map(c =&gt; parseInt(c))
      .reduce((a, b) =&gt; a + b)
  )
}


As it intuitively appears, the code above does the following:


convert the number into a string
split the string by the empty string, thus each digit/character of the string is an individual element of the new list
converts each digit from a string to an actual number
Reduces the list by the sum function


There are other ways of accomplishing this task, but I believe the above is rather easy to understand.