# Prime Number Program in JavaScript

## Prime Number Program in JavaScript

Using JavaScript you can easily write any programming code, Here we write one of the most popular program Prime Number Program in JavaScript. To perform this task we need for loop and if else condition.

## Prime Number Program in JavaScript

```<html>
<script type="text/javascript">

{

var beginNum = parseInt(document.numbers.firstNum.value);
var endNum = parseInt(document.numbers.secondNum.value);
var ctr = beginNum;
while(ctr<=endNum)
{
if(isPrime(ctr)==true)
{
}
ctr = ctr+1;
}
{
document.getElementById('output_content').innerHTML = "There were no prime no within the range.";
}
else
{
}
}
function isPrime(num)
{
var flag = true;
for(var i=2; i<=Math.ceil(num/2); i++)
{
if((num%i)==0)
{
flag = false;
break;
}
}
return flag;
}

{
var html = "<h2>Prime Numbers</h2>";
for (i=0;i<primes.length;i++){
html += primes[i] + "<br/>";
}
document.getElementById('output_content').innerHTML = html;
}

</script>
<body>
<form name="numbers">
Beginning Number: <input type="text" name="firstNum" />
End Number: <input type="text" name="secondNum" />
<input type="button" value="Find Prime Numbers" onclick="calcPrimeNumber()" />

</form>
<div id="output_content">
</div>
</body>
</html>
```

Start Number:

End Number: