The Digit Persistence

MediumAcc. 86.4%
+30 XP 12

Multiplicative Persistence

Multiply all the digits of a number. Take the result and repeat the process until you reach a single-digit number. The number of steps taken is the "multiplicative persistence." Example: 39 $ o 3 imes 9 = 27 o 2 imes 7 = 14 o 1 imes 4 = 4$. (3 steps).

The Assignment

Your function receives a parameter num.

  1. Initialize persistence to 0.
  2. Write a while loop that runs as long as num has more than one digit (num >= 10).
  3. Inside:
    • Calculate the product of all digits in num.
    • Update num with this product.
    • Increment persistence.
  4. After the loop, print the final persistence.

01EXAMPLE 1

Inputnum = 39
Output3

Explanation: 39 -> 27 -> 14 -> 4

Constraints

  • Use nested loops (one for steps, one for digit multiplication).
  • No strings allowed.
LoopsMathDigits
JavaScript
Loading...
3 Hidden

Input Arguments

num39

Expected Output

3

Click RUN to test your solution