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 % 10 slices 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.

  1. Use a while loop to extract and sum up all the digits of the number.
  2. Example: 123 becomes 1 + 2 + 3 = 6.
  3. Return the final sum.

Constraints

    CoreLoopsMath
    JavaScript
    Loading...
    3 Hidden

    Input Arguments

    num123

    Expected Output

    6

    Click RUN to test your solution