The Digit Crusher
Medium+25 XP
Mission Briefing
The dark crystals are stamped with massive serial numbers. Their actual power rating is the total sum of their individual digits. You must build a crusher to extract and add them!
The Concept: Mathematical Extraction
Using a while loop paired with math operators is a classic way to pull numbers apart:
num % 10slices off and gives you the exact last digit.Math.floor(num / 10)chops off the last digit from the original number so you can process the rest.
The Objective
Your function receives a positive integer num.
- Use a
whileloop to extract and sum up all the digits of the number. - Example:
123becomes1 + 2 + 3 = 6. - Return the final sum.
Constraints
CoreLoopsMath
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
num123
Expected Output
6
Click RUN to test your solution