|
| 1 | +--- |
| 2 | +title: Balance Transfer Calculator |
| 3 | +hide: |
| 4 | + - toc |
| 5 | +--- |
| 6 | +<script> |
| 7 | + function calculateTransfer() { |
| 8 | + // Get user input values |
| 9 | + let amountToTransfer = parseFloat(document.getElementById("amountToTransfer").value); |
| 10 | + const balanceTransferFee = parseFloat(document.getElementById("balanceTransferFee").value); |
| 11 | + const balanceTransferDuration = parseInt(document.getElementById("balanceTransferDuration").value); |
| 12 | + const plannedMonthlyPayment = parseFloat(document.getElementById("plannedMonthlyPayment").value); |
| 13 | + // Check if any fields are empty |
| 14 | + if (!amountToTransfer || !balanceTransferFee || !balanceTransferDuration || !plannedMonthlyPayment) { |
| 15 | + document.getElementById("result").innerHTML = "<strong style='color: red;'>Please fill in all fields.</strong>"; |
| 16 | + return; // Exit the function if validation fails |
| 17 | + } |
| 18 | + // Initialise Variables |
| 19 | + let totalTimeToPay = 0; |
| 20 | + let feePaid = 0; |
| 21 | + const initialAmountToTransfer = amountToTransfer; |
| 22 | + |
| 23 | + while (amountToTransfer > plannedMonthlyPayment) { |
| 24 | + let amountTransferred = amountToTransfer * (1 + balanceTransferFee / 100); |
| 25 | + let totalTimeRequired = amountTransferred / plannedMonthlyPayment; |
| 26 | + |
| 27 | + if (totalTimeRequired > balanceTransferDuration) { |
| 28 | + feePaid += amountToTransfer * (balanceTransferFee / 100); |
| 29 | + amountToTransfer = amountTransferred - (plannedMonthlyPayment * balanceTransferDuration); |
| 30 | + totalTimeToPay += balanceTransferDuration; |
| 31 | + } else { |
| 32 | + totalTimeToPay += totalTimeRequired; |
| 33 | + amountToTransfer = amountTransferred - (plannedMonthlyPayment * totalTimeRequired); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // Display results |
| 38 | + const result = ` |
| 39 | + To pay off <strong>£${initialAmountToTransfer}</strong> using monthly payments of <strong>£${plannedMonthlyPayment}</strong> with a <strong>${balanceTransferDuration} months</strong> balance transfer renewed until the whole amount is paid off and each renewal has a balance transfer fee of <strong>${balanceTransferFee} %</strong>, one will pay a total fee of <strong>£${feePaid.toFixed(2)}</strong> and will need to make the monthly payment for <strong>${Math.round(totalTimeToPay)} months</strong>. |
| 40 | + |
| 41 | + Balance transfer will need to be renewed at least <strong>${Math.round(totalTimeToPay / balanceTransferDuration)} times</strong>. |
| 42 | + `; |
| 43 | + document.getElementById("result").innerHTML = result; |
| 44 | + } |
| 45 | +</script> |
| 46 | + |
| 47 | +## Balance Transfer Calculator |
| 48 | + |
| 49 | +<div class="grid cards" markdown> |
| 50 | +- **Amount to Transfer (£):** |
| 51 | + |
| 52 | + --- |
| 53 | + |
| 54 | + <input class="md-input" type="number" id="amountToTransfer" required> |
| 55 | + |
| 56 | +- **Balance Transfer Fee (%):** |
| 57 | + |
| 58 | + --- |
| 59 | + |
| 60 | + <input class="md-input" type="number" id="balanceTransferFee" required> |
| 61 | + |
| 62 | +</div> |
| 63 | + |
| 64 | +<div class="grid cards" markdown> |
| 65 | +- **Balance Transfer Duration (months):** |
| 66 | + |
| 67 | + --- |
| 68 | + |
| 69 | + <input class="md-input" type="number" id="balanceTransferDuration" required> |
| 70 | + |
| 71 | +- **Planned Monthly Payment (£):** |
| 72 | + |
| 73 | + --- |
| 74 | + |
| 75 | + <input class="md-input" type="number" id="plannedMonthlyPayment" required> |
| 76 | + |
| 77 | +</div> |
| 78 | + |
| 79 | +<p align="center"><a class="md-button" onclick="calculateTransfer()">Calculate <span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 2h10a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 2v4h10V4zm0 6v2h2v-2zm4 0v2h2v-2zm4 0v2h2v-2zm-8 4v2h2v-2zm4 0v2h2v-2zm4 0v2h2v-2zm-8 4v2h2v-2zm4 0v2h2v-2zm4 0v2h2v-2z"></path></svg></span></a></p> |
| 80 | + |
| 81 | + |
| 82 | +<p id="result"></p> |
| 83 | + |
0 commit comments