-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSalesTax.js
31 lines (28 loc) · 831 Bytes
/
SalesTax.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
/**
* Hitung pajak dari total penjualan
* function getSalesTax(price, tax)
*/
function getSalesTax(price, tax) {
if(isNaN(price) && !isNaN(tax)){
return "Price harus dalam angka"
}
else if(!isNaN(price) && isNaN(tax)){
return "Pajak harus dalam angka"
}
else if(isNaN(price) && isNaN(tax)){
return "Price & Pajak harus dalam angka"
}
else{
let sum=price+tax;
return "Total Sales : Rp."+price+"\nPajak : "+tax+"\nTotalHarga+Pajak : Rp."+sum;
}
}
console.log(getSalesTax("a", 1));//Price harus dalam angka
console.log(getSalesTax(500, "pajak"));//Price & Pajak harus dalam angka
console.log(getSalesTax("harga", "pajak"));//Pajak harus dalam angka
console.log(getSalesTax(4500, 5));
/**
Total Sales : Rp.4500
Pajak : 0.5
TotalHarga+Pajak : Rp.4505
*/