Prime no. In JavaScript

Write a program to accept a no. from user and print whether it is prime or not.

Enter A Number:
<HTML>
<HEAD><title>Prime no. In JavaScript</title>
<script> 
function chkprime()  
  {     var div  
       var no=parseInt(frm.t1.value)  
        for(div=2;div<no;div++)     
        {
          if(no%div==0)  
            break;  
       }
        if(div==no)     
         alert(no + " is Prime number")
       else 
       alert(no + " Not Prime number") 
         } 
 </script> 
</HEAD> <BODY>
<form name=frm> Enter A Number:<input type=text name=t1 />
<input type='button' value='Is Prime?' onclick="chkprime();">
</form> 
</BODY>
</HTML>

2 comments:

  1. Prime numbers are a special kind of natural numbers or positive integers which are exactly
    divisible by 1 and the number itself or such as 2,3,5,7 and 11.

    ReplyDelete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete

Thanks for visiting my Blog!

Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog