-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime.html
59 lines (52 loc) · 1.26 KB
/
prime.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Prime Number</title>
</head>
<body>
<h1 style="color: green">Prime number using while loop</h1>
<ul>
<li>2: Event prime number</li>
<li>3: Prime</li>
<li>4: Not Prime</li>
<li>5: Prime</li>
<li>6: Not prime</li>
<li>7: Prime</li>
<li>8: Not Prime</li>
<li>9: Not Prime</li>
<li>10: Not Prime</li>
</ul>
<p></p>
</body>
<script>
function isPrime(number) {
for (i = 2; i < number; i++) {
if (number % i == 0) {
// Number is even and not prime
return false;
}
}
// Number is prime
return true;
}
let check = 2; // 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
let count = 1; // 2 | 3 | 3 | 4 | 4 | 5 | 5 | 5 | 5 | 6
let prime = [];
while (count) {
if (count > 5) {
break;
} else if (isPrime(check)) {
prime.push(check);
// console.log(`${check}`); // 2, 3, 5, 7, 11
count++;
// if (count > 5) {
// break;
// }
}
check++;
}
console.log(`Prime Array is: ${prime}`);
</script>
</html>