12+ JavaScript Armstrong Checker & Finder Examples

This post contains a total of 12+ Hand-Picked JavaScript Armstrong Number Checker & Finder Examples with Source Code. All the Armstrong Number Checker & Finder examples are made using JavaScript and some of them uses a little bit of css for styling.

You can use the source code of these examples for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By $hardul B

Made by $hardul B. Simple JavaScript program to check if a number is Armstrong or not. ( Source )


<!DOCTYPE html>
<html>
    <head>
        <title>Armstrong number</title>
        <style>
            
h1{
    text-align:center;
    color:#F2EA02;
    font-family: "Courier New", Courier, monospace;
    background-color:#7B68EE;
}
#par{
    text-align:center;
    }
body{
    background-color:#7CFC00;
}
#calc
{
    text-align:center;
    background-color:#DC143C;
    color:yellow;
}
#arm
{
    text-align:center;
    background-color:#800080;
    color:yellow;
}


            </style>
    </head>
    <body>
        <h1>Armstrong number</h1>
        <p id="par">
            <input type="number"id="ent"value="entered number"></input>
            <input type="button" value="check"onclick="funccheck()"></input>
            </p>
            <div id="calc">
                
            </div>
        <div id="arm">    
       
        </div>
        <script>
function funccheck()
{
var num = parseInt(document.getElementById("ent").value);
var a=num;
var array= [];
var add=0;
while (num > 0) {
    array[array.length] = num % 10;
    num = parseInt(num / 10);
}

for(var i=0;i<array.length;i++)
{
add=add+(Math.pow(array[i],array.length));
}
document.getElementById("calc").innerHTML="You Input: "+a+"<br/> Number of digits: "+array.length+"<br/>Number after Addition: "+add;
if(a==add){
document.getElementById("arm").innerHTML="<hr/>"+a+" is an Armstrong Number";
}
else
{
    document.getElementById("arm").innerHTML="<hr/>"+a+" is not an Armstrong Number";
}
}

            </script>
    </body>
</html>

2. By Prashanth Kumar

Made by Prashanth Kumar. Basic Armstrong number checker. ( Source )

enter a number to check
20
153 is an armstrong number
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    <style>
        a {
    background:linear-gradient(to top right,#eaa,#aea,white);
    -webkit-color:transparent ;
    -webkit-background-clip:text;
    -webkit-text-stroke:0.2px red;
    font-size:150%;
}
body{
    text-align:center;
}
        </style>
    </head>
    <body>
      challenged from <a href="https://www.sololearn.com/learn/4708/?ref=app">jaydeep</a>
      <script>
          var inpt=prompt("enter a number to check",153);
var str=inpt;
var i=-1; 
var ans=0;
var no;

for(let a=0;a<inpt.length;a++){
no=ab();
ans+=no;
}

if(ans==inpt){
    alert(inpt+" is an armstrong number")
} else{
    alert(inpt+" is not an armstrong number")
}
//alert(a())
function ab(){
   
i++;
  return str[i]**str[str.length-1];

}
          </script>
      </body>
</html>

3. By CalviΥ²

Made by CalviΥ². The program print out all the Armstrong numbers that are between 0 to 100000. ( Source )

Armstrong numbers (fr 0 to 1000000): 0,1,2,3,4,5,6,7,8,9,153,370,371,407,1634,8208,9474,54748,92727,93084,548834
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    <style>
        body {
    
}

pre {
    white-space: pre-wrap;
}

#result {
    width: 80%;
    font-weight: 600;
    white-space: pre-wrap;
    word-wrap: break-word;
}
        </style>
    </head>
    <body>
       <pre>
Challenge - Amstrong number

Armstrong numbers are those numbers which are equal to the sum of the digits of the number each raised to the power of the number of digits in the number itself. There are 14 Armstrong numbers in the range 0-5000, which are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634.

Example: 153 = 1 * 1 * 1 + 5 * 5 * 5 + 3 * 3 * 3

Posted by BykaH                   
       </pre> 
       
       <div id="result">Computing now, please wait...</div>
    <script>
        window.onload = main;

function main () {
    var n = 1000000;
    var res = document.getElementById("result");
    res.innerText = `Armstrong numbers (fr 0 to ${n}): ` + getNums(n)
}


// alert("Armstrong numbers: " + getNums(600000));

function getNums(m) {
    var arr = [];
    for(var i=0;i<=m;i++) {
        if(armstrong(i)) arr.push(i);
    }
    return arr;
}

function armstrong(n) {
    var val = 0;
    var arr = n.toString().split("");
    var digits = arr.length;
    for(var i=0;i<digits;i++) {
        num = Number(arr[i]);
        var pow=1;
        for(var j=0;j<digits;j++) pow *= num;
        val += pow;
    }
    return val===n;
}
        </script>
    </body>
</html>

4. By Uni

Made by Uni. Simple Armstrong number checker, enter any number in the input field and click check to know if that number is a Armstrong or not. ( Source )

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    <style>
        h1{
    text-decoration:underline;
    text-align:center;
}
#quote{
    font-family:cursive;
    text-align:right;
    text-decoration:underline;
    color:blue;
}
html{
    background-color:lightblue;
}
hr{
    color:orange;
    border-color:orange;
}
        |</style>
    </head>
    <body>
        <h1><strong>Armstrong Numbers</strong></h1>
        <p id="consigne">

An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.

For instance, a 3 digit number will be considered an Armstrong number if the sum of the cubes of its digits is equal to the number itself. 

For example, 153 is an Armstrong number, as 1**3 + 5**3 + 3**3 = 153

Create a program to check whether a given number is an Armstrong number or not.
Also, create a program to print all Armstrong numbers in a given range.</p>
        <input id="nr" name="tel" type="tel" placeholder="Enter your number">
        <button id="press">Check</button>
        <p id="answer"></p>
        <hr>
        <p id="quote"><a href="https://www.sololearn.com/Profile/8412719">Made by uni</a></p>
        <hr>
        <p id="time"></p>
        <script>
            function printtime(){
    var o=document.getElementById("time");
    var d=new Date();
    var hour=d.getHours();
    var mins=d.getMinutes();
    var secs=d.getSeconds();
    o.innerHTML=hour+":"+mins+":"+secs;
}setInterval(printtime,1000);
        </script>
        <script>
            window.onload=function(){
var butt = document.getElementById("press");
butt.addEventListener("click",check);
function check(){
    var nr = document.getElementById("nr").value;
    var p=document.getElementById("answer");
    var sum=0;
    for(x of nr){
        sum+=Math.pow(x,nr.toString().length);
    }
    if(sum==nr){
        p.innerHTML=nr+" is an Armstrong number.";
    }else{
        p.innerHTML=nr+" is not an Armstrong number.";
    }
  }
}
            </script>
    </body>
</html>

5. By Gordon

Made by Gordon. This JavaScript program prints all the Armstrong numbers between 0 -500. ( Source )

[1] 
[1,153,370,371,407] 
console.log(JSON.stringify(new Array(500).fill(0).map((_,i)=>i+1).filter(d=>d===d.toString().split("").map(parseInt).reduce((a,d)=>a+d*d*d, 0))));

console.log(JSON.stringify(new Array(500).fill(0).map((_,i)=>i+1).filter(d=>d===d.toString().split("").map(Number).reduce((a,d)=>a+d*d*d, 0))));

6. By UnknownYmous

Made by UnknownYmous. The program outputs true if the input number is Armstrong. ( Source )

153
true
a=prompt();s=0;for(i=0;i<a.length;i++)s+=a[i]*a[i]*a[i];alert(s==a?true:false)

7. By 🌴Vincent Berger🌴

Made by 🌴Vincent Berger🌴. This JavaScript program takes input number and checks whether it is Armstrong or not in real time and outputs result in Realtime. ( Source )

<!-- CODED BY VINCENT BERGER -->
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <style>
            
body {
    text-align:center;
}
input {
    position:relative; top:20vh;
}
div#output {
    position:relative; top:25vh;
}
            </style>
    </head>
    <body>
        <input type="number"/>
        <div id="output"></div>
        <script>
            
alert("Contest Link: https://www.sololearn.com/learn/4708/?ref=app");

setI=setInterval((y,str,mult,pl,fin,f)=>{
    y=$("input").val();
    str=y.split("");
    mult=str.map((value)=>{
        plus=value.charAt(0)**3;
        return value.replace(value.charAt(0),plus);
    });
    pl=eval(mult.join("+"));
    fin=mult.toString().replace(/,/ig, " + ");
    function matc(str) {
        if(y==pl){
            str="<div id='valid'>Armstrong Number Found!</span>";
            return str;
        }
    }
    $("#output").html(fin+" = "+pl+matc());
},10);
            </script>
    </body>
</html>

8. By Jason Cooper

Made by Jason Cooper. Enter number in input box and click the act button to check if the number is Armstrong or not. ( Source )

<!DOCTYPE html>
<html>
    <head>
        <title>
            Armstrong Number [27 Sep 2017]
        </title>
    </head>
    <body>
        <div>
            Referencing:
            <a href="https://code.sololearn.com/cr10bh4uMNWi/?ref=app">
                Armstrong Number Detection
            </a>
        </div>
        <br />
        <div>
            Definition:
            <br />
            Given a number of size p,
            <br />the sum of the values created when raising each digit to the power of p
        </div>
        <hr>
        <div id="input">
            n: <input id="n" type="text" />
               <input type="button" value="act" onclick="doStuff()" />
        </div>
        <hr>
        <div id="result">
            result:
            <div id="body"></div>
        </div>
        <script>
            var doStuff = function(){
    var size = document.getElementById("n");
    if(size){
        var nval = size.value;
        var message = nval + " is ";
        message += isArmstrong(nval)?"": "NOT ";
        message += "an Armstrong Number";
        body.innerText = message;
    }
}

var sansChar = function(nval,char){
    if( nval.indexOf(char)>0){
        nval = nval.toString().split(char).reduce(function(a,b){
            return a + (b==char ? '' : b);
        },'');
    }
    return nval;
}

var isArmstrong = function(nval){
    var result = true;
    
    // handle commas
    nval = sansChar(nval,',');

    var isInteger = Number(nval) && Math.floor(nval)==nval;
    if(isInteger){
        var length = nval.toString().length;
        var chars = nval.toString().split('');
        var sum = chars.reduce(function(s,v){
            return s  + Math.pow(v,length);
        },0);
        result = (sum==nval);
    }
    return result;
}
            </script>
    </body>
</html>

9. By ThreeG

Made by ThreeG. ( Source )

Enter a number
1212
1212 is not Armstrong number.
n = prompt ("Enter a number");
sum = 0;
for(i=0; i<n.length; i++){
    digit = n[i];
    sum+=Math.pow(digit,n.length);
}
if(sum==n){
    alert(n+" is Armstrong number.")
}
else{
    alert(n+" is not Armstrong number.")
}

10. By DN Developer

Made by DN Developer. Insert number then press the click button. ( Source )

<!--Armstrong of a number-->
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script>
            function rev(){
                var n=Number(document.getElementById('t1').value);
          var num=n;
          var arm=0;
          var rem;
          
          while(n!=0)
          {
              rem=parseInt(n%10);
              rem=rem*rem*rem;
              arm=parseInt(arm+rem);
              n=parseInt(n/10);
              
          }
          
          if(num==arm)
          {
          document.getElementById('t2').innerHTML=num  + "is a armstrong";
              
          }
          else{
document.getElementById('t2').innerHTML=num    + "is not a armstrong";
          }
          
            }
        </script>
    </head>
    <body>
        <input type="text" id="t1">
        <input type="button" id="b1" value="click" onclick="rev()">
        <p>Result:</p>
        <p id="t2"></p>
    </body>
</html>

11. By Aniket Gade

Made by Aniket Gade. JavaScript Armstrong checker with css styling. ( Source )

<!DOCTYPE html>
<html>
    <head>
    <style type="text/css">
    </style>
        <title>Page Title</title>
        <script type="text/javascript">
        </script>
        <style>
            *{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

html
{
    font-size:62.5%;
}


body {
    width:100vw;
    height:100vh;
    background-color:pink;
    display:grid;
    place-items:center;
}


h2{
    width:100%;
    color:red;
    font-size:2.6rem;
    background-color:yellow;
    padding:2rem 0rem;
    text-align:center;
    position:absolute;
    top:0;
}



#text1{
    width:33rem;
    height:5rem;
    color:orange;
    outline:none;
    border:.3rem solid #fff;
    padding:3rem 2rem;
    font-size:2rem;
    background-color:#000;
    border-radius:2rem;
    
}


#btn1{
    font-size:3rem;
    color:#fff;
    font-style:bold;
    position:absolute;
    top:70%;
    left:50%;
    transform:translateX(-50%);
    outline:none;
    border:none;
    background-color:blue;
    border-radius:3rem;
    padding:2rem 4rem;
}

::placeholder
{
    color:#fff;
}

#text1:focus::placeholder
{
    opacity:0;
}
            </style>
    </head>
    <body>
  <h2>
  <b>Armstrong Number Checker
</b>
    </h2>
    <br />
    <br />
    <center>
        <input type="number" id="text1" placeholder="Enter any Number...">
        </center>
        <br />
        <br />
        <center>
        <button onclick="f1()" id="btn1">Verify</button>
        </center>
        <script>
                      function f1()
            {
            var a,r,renum=0,n;
               a = parseInt(document.getElementById("text1").value);
               n=a;
              while(a>0)
       
              {
                 r=a%10;
                renum=renum+r*r*r;
                a=parseInt(a/10);
              }
              if(n==renum)
              {
                  document.write("<h1 style=color:#0000ff>Hey,Your Enterd number "+n+" is Armstrong Number...</h2>");
              }
              else
              {
                  document.write("<h1 style=color:#880000>Hmm,Your Enterd number "+n+" is not Armstrong Number..</h1>")
              }""
            }
            </script>
    </body>
</html>

12. By Saurabh Tiwari

Made by Saurabh Tiwari. ( Source )

Enter a No.
371
Yes! It is an Armstrong No.
var n,x,s=0,r
n=prompt("Enter a No.")
x=n
while(x!=0)
{
    r=x%10
    s+=Math.pow(r,Math.floor(Math.log10(n))+1)
    x=parseInt(x/10)
}
s==n?document.write("Yes! It is an Armstrong No."):document.write("No")

13. By ODG

Made by ODG. ( Source )

Testing number ?
123
123 isn't an Armstrong Number
<!DOCTYPE html>
<html>
    <head>
        <title>Armstrong Numbers</title>
        <meta name="Started" content="20180228">
    </head>
    <body>
        
    </body>
    <script>
            document.write("<center><table width=100% cellpadding=0 cellspacing=0><tr><th style='color:lime;background:green'>&nbsp;Armstrong Numbers'20180906 &copy; ODG, 2018&nbsp;</th></tr>")
    document.write("</table></center><br>")

    n=prompt('Testing number ?',153)

    with(Math)
      {
        h=floor(n/100)
        d=floor((n-100*h)/10)
        o=n%10
      }
      document.write(n,' is',(h*h*h+d*d*d+o*o*o==n)?' the':'n\'t an',' Armstrong Number<br>')

    document.write('<br><br>Done !<br><br><img src="data:image/gif;base64,R0lGODlhLwAPAPcAAAD/AAAAAACAAIAAAP//AP8AAICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAEALAAAAAAvAA8ABwjXAAMIHEiwoMEABQYcXMiwoICHCxUOTNiwosGHADJCLEjxIEUDIA8+FCBSI0YAJCMOkBhAogECBEIKPInSocmRGg2uLMBzJcGXMGMGEJCxaMqBRGliPDpwAM+nLAMAhWlgqNGNMzWaRJnTp9OnUAdOpXp1JESiXGueJMmzJdiwPMfGNFo0J9q7SXM2fduz5QC5Bq7WTZkULcqkOt9GHVvVsOGaVg/jhExwZ8/FQYU+Hoz0pt6mTX0WBCpzqGPESE8XdBqxgECQVS9uxJqaaevKFnPrdrubYUAAOw==" alt="" border=no align=absmiddle />')

        </script>
</html>