logo CodeStepByStep logo

computeSumOfDigits

Language/Type: JavaScript cumulative algorithms fencepost while loops

Write a function named computeSumOfDigits that takes an integer as a parameter and returns the sum of the digits of that integer. You may assume that the value passed is a non-negative integer. For example, the call computeSumOfDigits(827104) should return 22, since 8 + 2 + 7 + 1 + 0 + 4 = 22.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.