← All Exercises

Sum of Digits

basicjavascript~10min

Background

Digit summing appears in checksums, digital root calculations, and number theory problems.

Problem

Write a function that takes a non-negative integer and returns the sum of its individual digits.

Input

A non-negative integer.

Output

A non-negative integer representing the sum of all digits.

Sample tests

Sample 1

Input: 12345
Expected: 15

Your solution

Learning objective

Practice type conversion between strings and numbers for digit-level operations.