The Digit Dissolver

EasyAcc. 95.6%
+20 XP 8

Breaking Numbers Down

Numbers are made of digits. By using the modulo operator to extract the last figure and mathematical division to remove it, you can iterate through any number until nothing is left.

The Assignment

Your function receives a parameter named number.

  1. Declare a let variable sumOfDigits initialized to 0.
  2. Write a do-while loop that continues as long as number is greater than 0.
  3. Inside the do block:
    • Identify the last digit of the current number.
    • Add that digit to sumOfDigits.
    • Trim the last digit from the number, ensuring the result is treated as a solid integer.
  4. After the loop, print sumOfDigits.

01EXAMPLE 1

Inputnumber = 425
Output11

Explanation: 4 + 2 + 5 = 11.

Constraints

  • Use a do-while loop.
  • Use Math.floor() for the division step.
LoopsMath
JavaScript
Loading...
3 Hidden

Input Arguments

number425

Expected Output

11

Click RUN to test your solution