<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>JS Armstrong Number</h1>
<script>
var num = 19;
var copyNum = num;
var digits = 0;
var remainder = 0;
var total = 0;
//find number of digits in num variable
while(copyNum != 0)
{
digits++;
copyNum = Math.floor(copyNum / 10);
}
copyNum = num;
//slice the numbers from last digits
while(copyNum != 0)
{
remainder = copyNum % 10;
total += Math.pow(remainder, digits);
copyNum = Math.floor(copyNum / 10);
}
//result
if(num == total)
document.write(num +" is an armstrong number");
else
document.write(num +" is not an armstrong number");
</script>
</body>
</html>