-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassignment4.html
More file actions
39 lines (36 loc) · 1.19 KB
/
Copy pathassignment4.html
File metadata and controls
39 lines (36 loc) · 1.19 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Check a number is prime number</title>
</head>
<body>
<input type="text" id="number">
<button onclick=checkPrime()>Submit</button>
<script>
function checkPrime() {
let check = document.getElementById("number").value;
check = parseInt(check);
let isPrime, value;
if(check === 2 || check === 3) {
isPrime = true
}
for(let i = 2; i < check; i++) {
isPrime = true;
if(check % i === 0) {
isPrime = false;
value = i;
break;
}
}
if(isPrime === true) {
alert(check + " is a prime number!");
} else {
alert(check + " is not a prime number! as it is also a multiple of " + value);
}
}
</script>
</body>
</html>