JavaScript and HTML code to check whether given number is prime or not - Practical [ SWPD 4311603 ]

 Practical Aim:

JavaScript and HTML code to check whether given number is prime or not

Sample output:
check whether given number is prime or not javascript


First, try at own

Code

number_prime_notprime_javascript.html file

Untitled Document

<html>
<head>
<title>JavaScript sum 1 to n Number</title>
<style>
button {
background-color: black;
border: none;
color: white;
padding: 10px 10px;
text-align: center;
text-decoration: none;
font-size: 15px;
cursor: pointer;
border-radius: 12px;
}

</style>
<script>
function Prime()
{
var i,flag=0,number;
number = Number(document.getElementById("enterednumber").value);

for(i=2; i <= number/2; i++)
{
if(number%i == 0)
{
flag = 1;
break;
}
}
if(flag == 0)
{
window.alert(number+" Entered number is Prime");
}
else
{
window.alert(number+" Entered number is not Prime");
}
}
</script>
</head>
<body>
<br>
<h1>Whether a number is Prime or not</h1>
Enter The Number :<input type="text"id = "enterednumber"/>
<hr color="cyan">
<br>
<button onClick="Prime()">CHECK</button>
</body>
</html>


Try here

<!DOCTYPE html >
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h1> Try your code here</h1>
</body>
</html>



Output


Post a Comment

0 Comments