The Armstrong Ascent
MediumAcc. 88.7%
+25 XP 10
Narcissistic Numbers
An Armstrong Number (or narcissistic number) is a number that is the sum of its own digits each raised to the power of the number of digits. Example: $153$ ($3$ digits) $ o 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153$.
The Assignment
Your function receives a parameter named target.
- Determine the number of digits in
target(call thisn). - Use a loop to extract each digit of the number.
- Raise each digit to the power of
nand add it to atotal. - Print "true" if
totalequalstarget, otherwise print "false".
01EXAMPLE 1
Input
target = 153Output
trueExplanation: 1^3 + 5^3 + 3^3 = 153
Constraints
- Extract digits mathematically (use % and Math.floor).
- Handle variable number of digits.
MathLoopsDigits
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
target153
Expected Output
true
Click RUN to test your solution