198
rated 0 times
[
200]
[
2]
/ answers: 1 / hits: 18660
/ 7 Years ago, thu, august 31, 2017, 12:00:00
I need to do a code to verify whether or not the entered number is an Armstrong number, but my code does not work for every number.
Could anyone tell me what am I missing? Are there any other ways to do this?
Thank you!
let e, x, d = 0;
let b = prompt(Enter a number);
x=b;
while (x > 0) {
e = x % 10;
x = parseInt(x/10);
d = d + (e*e*e);
}
if (b==d)
alert(given number is an armstrong number);
else
alert(given number is not an armstrong number);
<!DOCTYPE HTML>
<html>
<head>
<title>Armstrong</title>
</head>
<body>
</body>
</html>
More From » javascript