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.
- Declare a let variable
sumOfDigitsinitialized to 0. - Write a
do-whileloop that continues as long asnumberis greater than 0. - Inside the
doblock:- 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.
- After the loop, print
sumOfDigits.
01EXAMPLE 1
Input
number = 425Output
11Explanation: 4 + 2 + 5 = 11.
Constraints
- Use a do-while loop.
- Use Math.floor() for the division step.
LoopsMath
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
number425
Expected Output
11
Click RUN to test your solution