Getting going, Loops
Add up the digits
The task
Add up the digits of a whole number that is 0 or more. 1234 gives 10.
One way: take the last digit with % 10, then drop it with whole-number division by 10.
Write a function called sumDigits.
Tests
| Call | Expected | Yours |
|---|---|---|
sumDigits(1234) |
10 |
not run |
sumDigits(9) |
9 |
not run |
sumDigits(1000) |
1 |
not run |
sumDigits(0) |
0 |
not run |
sumDigits(98765) |
35 |
not run |
solution.js
Tab indents. To leave the editor, press Escape, then Tab.
Output
Run prints what your code prints. Run the tests to check your function.