-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexercise2.html
74 lines (63 loc) · 2.46 KB
/
exercise2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script>
// Minta kuantitas 3 buah
// Kalkulasi total harga = harga * kuantitas
// Stock Buah
// Apabila salah satu buah stock nya kurang maka transaksi dibatalkan
var qtyApel, qtyGrape, qtyOrange; // minta dari user
var stockApel, stockGrape, stockOrange;
var hargaApel = 10000;
var hargaGrape = 15000;
var hargaOrange = 20000;
stockApel = 7;
stockGrape = 5;
stockOrange = 4;
qtyApel = prompt('Masukkan jumlah Apel Rp. ' + hargaApel + '\nStok Apel: ' + stockApel);
if(qtyApel > stockApel){
alert('Error');
qtyApel = null;
}else if(qtyApel < 0){
alert('kuantitas tidak bisa dibawah 0')
}
qtyGrape = prompt('Masukkan jumlah Anggur Rp. ' + hargaGrape + '\nStok Anggur: ' + stockGrape);
if(qtyGrape > stockGrape || qtyGrape < 0){
alert('Error');
qtyGrape = null;
}
qtyOrange = prompt('Masukkan jumlah Jeruk Rp. ' + hargaOrange + '\nStok Jeruk: ' + stockOrange);
if(qtyOrange > stockOrange || qtyOrange < 0){
alert('Error');
qtyOrange = null;
}
if(qtyApel === null || qtyGrape === null || qtyOrange === null){
alert("Transaksi dibatalkan, terjadi kesalahan di salah satu input")
}
else if(qtyApel == 0 && qtyGrape == 0 && qtyOrange == 0){
alert('Mohon input kuantitas barang di kasir');
}
else{
var totalApple = hargaApel * parseInt(qtyApel);
var totalGrape = hargaGrape * parseInt(qtyGrape);
var totalOrange = hargaOrange * parseInt(qtyOrange);
var totalPrice = totalApple + totalGrape + totalOrange;
alert(
'Detail Transaksi \n\n' +
'Apel: ' + qtyApel + ' x ' + hargaApel + ' = ' + totalApple + '\n' +
'Anggur: ' + qtyGrape + ' x ' + hargaGrape + ' = ' + totalGrape + '\n' +
'Jeruk: ' + qtyOrange + ' x ' + hargaOrange + ' = ' + totalOrange + '\n\n' +
'Total : Rp.' + totalPrice
)
var money = prompt('Masukkan jumlah uang \nTotal Biaya = Rp. ' + totalPrice);
var margin = money - totalPrice;
// Uang lebih
// Uang kurang
// Uang pas
// Nested Condition
if(money > totalPrice){
alert('Terima Kasih \nKembalian anda sebesar Rp. ' + margin);
}else if(money < totalPrice){
alert('Transaksi dibatalkan, uang anda tidak mencukupi Rp.' + margin);
}else{
alert('Terima Kasih, uang pas')
}
}
</script>