-
Notifications
You must be signed in to change notification settings - Fork 5
/
primeNumber.html
44 lines (39 loc) · 1.01 KB
/
primeNumber.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prime Number</title>
<script type="text/javascript">
function isPrime()
{
var set = 0;
var num = document.getElementById("num").value;
document.getElementById("answer").innerHTML = "";
for(i=2; i<Math.sqrt(num);i++)
{
if(num % i == 0)
{
set = 1;
break;
}
}
if(set == 1)
{
document.getElementById("answer").innerHTML +="<h1 style='color:red'>Not a Prime !!!</h1>";
}
else
{
document.getElementById("answer").innerHTML +="<h1 style='color:green'>Prime !!!</h1>";
}
}
</script>
</head>
<body>
<div class="input-group">
<span class="input-group-addon"></span>
<input type="number" class="form-control" id="num" placeholder="Enter the number">
<button onclick="isPrime()">Check</button>
<p id="answer"></p>
</div>
</body>
</html>