Computer Science, asked by arbindverma80, 5 months ago

what is javascript program display wheather a number is prime or not​

Answers

Answered by anindyaadhikari13
3

Question:-

➡ Write a JavaScript program to display whether a number is prime or not.

Program:-

➡ First of all, write this HTML code and then add the JavaScript code inside head using script tag. I am writing them separately.

This is the html code.

<!DOCTYPE html>

<html>

<head>

<title>HTML/JavaScript Code to check prime.</title>

<meta name="viewport" content="width=device-width, initial-scale=1" />

</head>

<body>

</body>

</html>

Now, write the JavaScript code inside script tag.

var x=parseInt(prompt("Please enter an integer number: ", ""))

if (x!=null)

{

var c=0;

for(var a=1;a<=x;a++)

{

if(x%a==0)

c=c+1

}

if (c==2)

alert("The number you entered is Prime.");

else

alert("The number is not Prime.");

Similar questions