From c78406f1c7d77043f749155dd46ce2199d5e0f4c Mon Sep 17 00:00:00 2001
From: Jymma
- {amount}
+ {formatMoney(amount)}
@@ -78,10 +90,11 @@ function App() {
{months} Months
- total Total to pay + {formatMoney(total)} Total to + pay
- pay Monthly + {formatMoney(pay)}Monthly
diff --git a/src/helpers/index.js b/src/helpers/index.js new file mode 100644 index 0000000..ad1b739 --- /dev/null +++ b/src/helpers/index.js @@ -0,0 +1,31 @@ +const formatMoney = (value) => { + const formatter = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + }); + return formatter.format(value); +}; + +const calculateTotalPay = (amount, term) => { + let total; + + if (amount < 5000) { + total = amount * 1.5; + } else if (amount >= 5000 && amount < 10000) { + total = amount * 1.4; + } else if (amount >= 10000 && amount < 15000) { + total = amount * 1.3; + } else { + total = amount * 1.2; + } + + if (term === 6) { + total *= 1.1; + } else if (term === 12) { + total *= 1.2; + } else { + total *= 1.3; + } + return total; +}; +export { formatMoney, calculateTotalPay };