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.

  1. Determine the number of digits in target (call this n).
  2. Use a loop to extract each digit of the number.
  3. Raise each digit to the power of n and add it to a total.
  4. Print "true" if total equals target, otherwise print "false".

01EXAMPLE 1

Inputtarget = 153
Outputtrue

Explanation: 1^3 + 5^3 + 3^3 = 153

Constraints

  • Extract digits mathematically (use % and Math.floor).
  • Handle variable number of digits.
MathLoopsDigits
JavaScript
Loading...
3 Hidden

Input Arguments

target153

Expected Output

true

Click RUN to test your solution