Write a JavaScript program to check the given number is Armstrong or Not

3 years ago

Write a JavaScript program to check the entered number is Armstrong or not. Note: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

<!doctype html>
<html>
<head>
	<title>Armstrong Number or Not</title>
</head>
<body>
	<br>
	Enter any Number: <input id="no_input">
	<button onclick="armstr()">Check</button></br></br>

<script>
	function armstr(){
		var arm=0,a,b,c,d,num;
		num=Number(document.getElementById("no_input").value);
		temp=num;
		
		while(temp>0){
			a=temp%10;
			temp=parseInt(temp/10); // convert float into Integer
			arm=arm+a*a*a;
		}

		if(arm == ''){
			alert('Please enter any Number')
		}
		else if(arm==num){
			alert("Armstrong number");
		}else{
			alert("Not Armstrong number");
		}
	}
</script>
</body>
</html>
  3240