forked from nhattruongniit/learn-javascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi-dont-know-js.js
More file actions
30 lines (27 loc) · 760 Bytes
/
i-dont-know-js.js
File metadata and controls
30 lines (27 loc) · 760 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
const SPENDING_THRESHOLD = 200;
const TAX_RATE = 0.08;
const PHONE_PRICE = 99.99;
const ACCESSORY_PRICE = 9.99;
var bank_balance = 303.91;
var amount = 0;
function calculateTax(amount){
return amount * TAX_RATE;
}
function formatAmount(amount) {
return '$' + amount.toFixed(2);
}
// còn tiền thì mua tiếp
while(amount < bank_balance) {
//mua dt
amount = amount + PHONE_PRICE;
//chung ta co the mua phụ kiện dc ko?
if(amount < SPENDING_THRESHOLD) {
amount = amount + ACCESSORY_PRICE;
}
}
// đừng quên trả tiền cho chính phủ
amount = amount + calculateTax(amount);
console.log("Your purchase: " + formatAmount(amount));
if(amount > bank_balance) {
console.log("You can't afford this purchase.")
}