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.
- Initialize
persistenceto 0. - Write a
whileloop that runs as long asnumhas more than one digit (num >= 10). - Inside:
- Calculate the product of all digits in
num. - Update
numwith this product. - Increment
persistence.
- Calculate the product of all digits in
- After the loop, print the final
persistence.
01EXAMPLE 1
Input
num = 39Output
3Explanation: 39 -> 27 -> 14 -> 4
Constraints
- Use nested loops (one for steps, one for digit multiplication).
- No strings allowed.
LoopsMathDigits
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
num39
Expected Output
3
Click RUN to test your solution