Showing posts with label armstrong number in javascript. Show all posts
Showing posts with label armstrong number in javascript. Show all posts

Tuesday, February 6, 2018

Armstrong Number in JavaScript

Here is a sample program that will check if the given number is an Armstrong Number or Not using JavaScript. I hope you will find my work useful.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.






Sample Program Output


Program Listing

index.htm


<!--
 Written By Mr. Jake R. Pomperada, MAED-IT
 February 6, 2018   04:24 PM   Tueday
 Bacolod City, Negros Occidental Republic of the Philippines
 jakerpomperada@yahoo.com and jakerpomperada@gmail.com -->
<!doctype html>
<html>
<head>
<title> Armstrong Number in JavaScript </title>
<style>

   .art {

      font-family: arial;
      font-weight: bold;
      color:red;
      text-align: center;
      width:45%;
      background-color:yellow;
   }

.art2 {

      font-family: arial;
      font-weight: bold;
      font-size: 25px;
      color:blue;
      text-align: center;
      width:45%;
      background-color:lightgreen;
   }

   body {
     font-family: arial;
     font-weight: bold;
     font-size: 20px;
   }

   #button_me {
    background-color: #008CBA;
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
    height: 50px;
    width: 120px
     text-align: center;
    cursor: pointer;
 }

 input[type=text] {
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
   
 }
</style>
      
<script>

function armstrong()
{

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==num)
{

 document.getElementById("msg").innerHTML = "The given number " + num
 + " is a Armstrong number.";
}
else
{
document.getElementById("msg").innerHTML = "The given number " + num
 + " is Not a Armstrong number.";
}
}
</script>

<script>
function clear_me()
{
document.getElementById("msg").innerHTML = "";
document.getElementById("no_input").value = "";
document.getElementById("no_input").focus();
}
</script>

</head>
<body>
<h1 class="art"> Armstrong Number in JavaScript </h1>
    <p  class="art2"> Created By Mr. Jake R. Pomperada, MAED-IT </p>
<br><br>
Give a Number <input id="no_input" type="text" size="5" autofocus>
<br><br>
<p id="msg"> </p> 
<button id="button_me" onclick="armstrong()">Check</button>
&nbsp;&nbsp;&nbsp;
<button id="button_me" onclick="clear_me()">Clear</button>
</br></br>
</body>
</html>