Sum of Digits
Add up every digit of a number: 123 β 1 + 2 + 3 = 6. Convert to a string, split,
and reduce. Use Math.abs so negatives work too.
Your task
Write sumDigits(n) that returns the sum of the digits of n.
β‘ 35 XP
solution.jsRuns in your browser
Loading editorβ¦
Tests3 to pass
sumDigits(123) === 6
sumDigits(0) === 0
sumDigits(99) === 18
Run your code to check these.