-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (33 loc) · 861 Bytes
/
script.js
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
function checkPrime(num) {
if (num <= 1) {
return false;
}
for (
let i = 2;
i <= Math.sqrt(num); i++
) {
if (num % i === 0) {
return false;
}
}
return true;
}
document.getElementById("submit").addEventListener("click", (event) => {
event.preventDefault()
let num =
document.getElementById("inp").value;
let result = checkPrime(num);
if (result) {
document.getElementById("dom-msg").innerHTML =
num + " Is A Prime Number";
} else {
document.getElementById("dom-msg").innerHTML =
num + " Is Not A Prime Number";
}
}
);
document.getElementById("clear")
.addEventListener("click", () => {
document.getElementById("inp").value = "";
document.getElementById("dom-msg").innerHTML = "Result";
})