JavaScript program to check if a number is an Armstrong number:

Created with Sketch.

JavaScript program to check if a number is an Armstrong number:

let number = 153;
let originalNumber = number;
let sum = 0;
let digits = 0;

while (originalNumber !== 0) {
  originalNumber = Math.floor(originalNumber / 10);
  digits++;
}

originalNumber = number;

while (originalNumber !== 0) {
  let remainder = originalNumber % 10;
  sum += Math.pow(remainder, digits);
  originalNumber = Math.floor(originalNumber / 10);
}

if (number === sum) {
  console.log(number + " is an Armstrong number");
} else {
  console.log(number + " is not an Armstrong number");
}

Leave a Reply

Your email address will not be published. Required fields are marked *