-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex8.html
More file actions
37 lines (34 loc) · 718 Bytes
/
Copy pathex8.html
File metadata and controls
37 lines (34 loc) · 718 Bytes
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
<DOCTYPE! html>
<html>
<head>
<meta charset="UTF-8" ; />
<title>Exercise 8</title>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
let i = 3,
count,
c;
let n = 20;
if (n >= 1) {
document.write("First " + n + " prime numbers are :\n");
}
for (count = 2; count <= n;) {
for (c = 2; c <= i - 1; c++) {
if (i % c == 0) break;
}
if (c == i) {
document.write(i + " ");
count++;
}
i++;
}
return 0;
}
</script>
</body>
</html>
</DOCTYPE!>