-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05.js
More file actions
73 lines (53 loc) · 1.16 KB
/
Copy path05.js
File metadata and controls
73 lines (53 loc) · 1.16 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let number = [];
for (let i=0; i<=1000; i++ ){
number.push(i);
}
let ganjil =[];
let genap =[];
let kelipatan = [];
let temprima =[];
let prima100 = [];
var i=0;
function ganjilgenap(){
for (i=0; i<number.length; i++){
if(number[i] % 2 === 0){
genap.push(number[i]);
} else {
ganjil.push(number[i]);
}
}
};
function kelipatan5(){
for (i=0; i<number.length; i++){
if(number[i] % 5 === 0){
kelipatan.push(number[i]);
}
}
};
function prima(num) {
for (i = 2; i < num; i++) if (num % i === 0) return false;
return num >1;
}
function primaok() {
number.forEach(e => {
if(prima(e)) {
temprima.push(e);
}
});
}
function primas100(){
for (i=0; i<temprima.length; i++){
if (temprima[i] <= 100){
prima100.push(temprima[i]);
}
}
}
ganjilgenap();
kelipatan5();
primaok();
primas100();
console.log(`Bilangan ganjil : ${ganjil}`);
console.log(`Bilangan genap : ${genap}`);
console.log(`Kelipatan 5 : ${kelipatan}`);
console.log(`Prima : ${temprima}`);
console.log(`Bilangan Prima dibawah 100 : ${prima100}`)