first n prime numbers in JavaScript
<body>
<script>
var n;
var status=1;
var num=3;
n=prompt("enter the limit");
if(n>=1)
{
document.write("2"+"</br>") ///2 is an prime number that we have know
}
for(var i=2;i<=n; )
{
for(var j=2;j<=Math.sqrt(num);j++)
{
if(num%j==0)
{
status=0;
break;
}
}
if(status !=0)
{
document.write(num+"</br>");
i++;
}
status=1;
num++;
}
</script>
</body>
</html>
output
If give 10 as limit