JavaScript Program to check a number is Armstrong or not

In this program, You will learn how to check a number is Armstrong or not in JavaScript.


while(condition){
    //statement
    //Increment/Decrement
}

JavaScript Program to check a number is Armstrong or not

Example: How to check a number is Armstrong or not in JavaScript

let num = n = parseInt(prompt("Enter 3 digit number:"))
let rev = 0, r;

rev = 0;
while (n > 0) {
  r = n % 10;
  rev = rev + r * r * r;
  n = parseInt(n / 10)
}

if (num == rev) {
  console.log("Number is ArmStrong:" + num)
} else {
  console.log("Number is not ArmStrong:" + num)
}

Output:

Enter 3 digit number:> 153
Number is ArmStrong:153