Prime Numbers upto the input number

Prime numbers are having only two factors, one is 1 and other one is the number itself.

These are the first 5 prime numbers 2, 3, 5, 7, 11

Prime numbers are divisible by exactly two natural numbers.

Enter any number


Output here
<html>
<head>
<title></title>
</head>
<body>
<input type="text" name="t1" id="t1">
<input type="button" value="Submit" onclick="show_prime()">
<div id=d1></div>
<script type="text/javascript">
function show_prime(){
x=document.getElementById("t1").value
x=parseInt(x)
if(Number.isInteger(x)){
str='';
for (i=2;i<x;i++){
  flag=0;
	
  for(j=2;j<i;j++){
	if(i%j == 0){
	flag=1;
	break;
	}
	
  }	
 if(flag==0){
	str= str + i + ","
}

}
document.getElementById('d1').innerHTML="Series is :  " + str
}else{
document.getElementById('d1').innerHTML="Enter an Integer  "	
}
}
</script>
</body>
</html>
isInteger()Checking if input number is integer or not
parseInt()function to convert string to number
Next lower value of any decimal number JavaScript Basic JavaScript variable
JavaScript Math Reference

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer