Sum of digits
EasyNumbers · JavaScript
The task
Write sumDigits(n) that returns the sum of the digits of the non-negative integer n.
For example 1234 gives 1 + 2 + 3 + 4 = 10.
Examples
- sumDigits(1234) returns 10
- sumDigits(0) returns 0
Your code runs in your browser, in a separate worker, and is never sent to us. Edit the function, then press Run tests. Your work is saved here as you type.
JavaScriptCtrl or Cmd + Enter to run