Write a program in JavaScript to generate series of prime number.

Method 1

<html>

<head>

<title>M2-R5.1 Set 2 Question 3</title></head>

<body>

<script>

      start=parseInt(prompt(“Enter the Starting Number”));

      stop=parseInt(prompt(“Enter the ending number”));

let count=0

let i,j

for(j=start;j<=stop;j++)

{

for( i=1;i<=j;i++)

{

  if(j%i==0)

  count++

 }

if(count==2)

document.write(j+” “)

count=0

}

</script>

</body>

</html>

 

Method 2

<html>

<head>

<title>M2-R5.1 Set 2 Question 3</title></head>

<body>

<script>

      start=parseInt(prompt(“Enter the Starting Number”));

      stop=parseInt(prompt(“Enter the ending number”));

for(n=start;n<=stop;n++)

{

var prime=true;

for(var i=2;i<n-1;i++)

{

if(n%i==0)

{

prime=false;

break;

}

}

if(prime==true)

document.write(n+” , “);

}

</script>

</body>

</html>