-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.js
48 lines (39 loc) · 1.1 KB
/
2.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
36
37
38
39
40
41
42
43
44
45
46
47
48
let id = "3888-I-0197621";
let totalMember = 21;
// write your code here
let citizen = ''
// cek I dan A pada id
for (let i = 0; i < id.length; i++) {
if (id[i] === 'I') {
citizen = 'wni'
} else if (id[i] === 'A') {
citizen = 'wna'
}
}
// console.log(citizen);
// cek jumlah anggota dan harga
if (citizen.length === 0) {
console.log(`Anda tidak terdaftar`);
} else {
let totalHarga
let hasil
if (citizen === 'wni') {
let harga = 20_000 // per orang
let hargaDasar = harga * totalMember
if (totalMember > 20) {
totalHarga = hargaDasar - (0.2 * hargaDasar)
} else {
totalHarga = hargaDasar
}
} else if (citizen === 'wna') {
let harga = 50_000 // per orang
let hargaDasar = harga * totalMember
if (totalMember > 30) {
totalHarga = hargaDasar - (0.2 * hargaDasar)
} else {
totalHarga = hargaDasar
}
}
hasil = `Karena anda adalah ${citizen}, maka tagihan untuk id ${id} adalah ${totalHarga}`
console.log(hasil);
}