Skip to content

Commit

Permalink
Update balance_transfer_calc.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pubmania authored Jan 9, 2025
1 parent 931e11b commit 4d68b81
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/resources/balance_transfer_calc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,48 @@ hide:
const balanceTransferFee = parseFloat(document.getElementById("balanceTransferFee").value);
const balanceTransferDuration = parseInt(document.getElementById("balanceTransferDuration").value);
const plannedMonthlyPayment = parseFloat(document.getElementById("plannedMonthlyPayment").value);

// Check if any fields are empty
if (!amountToTransfer || !balanceTransferFee || !balanceTransferDuration || !plannedMonthlyPayment) {
document.getElementById("result").innerHTML = "<strong style='color: red;'>Please fill in all fields.</strong>";
return; // Exit the function if validation fails
}

// Initialise Variables
let totalTimeToPay = 0;
let feePaid = 0;
const initialAmountToTransfer = amountToTransfer;
let counter = 0;
let breakdownString = "";

while (amountToTransfer > plannedMonthlyPayment) {
counter += 1;
let amountTransferred = amountToTransfer * (1 + balanceTransferFee / 100);
let totalTimeRequired = amountTransferred / plannedMonthlyPayment;

if (totalTimeRequired > balanceTransferDuration) {
breakdownString += `<li> Amount to balance transfer in <strong>Year ${counter}</strong> with fee included: <strong>£${amountTransferred.toFixed(2)}</strong></li>`;
feePaid += amountToTransfer * (balanceTransferFee / 100);
amountToTransfer = amountTransferred - (plannedMonthlyPayment * balanceTransferDuration);
totalTimeToPay += balanceTransferDuration;
totalTimeToPay += 12;
} else {
totalTimeToPay += totalTimeRequired;
amountToTransfer = amountTransferred - (plannedMonthlyPayment * totalTimeRequired);
let finalPaymentAmountWithFee = plannedMonthlyPayment * totalTimeRequired;
breakdownString += `<li> Amount to balance transfer in <strong>Year ${counter}</strong> with fee included: <strong>£${finalPaymentAmountWithFee.toFixed(2)}</strong></li>`;
let finalPaymentAmount = finalPaymentAmountWithFee * 0.65;
breakdownString += `<li> Amount to finish by one time payment in <strong>Year ${counter}</strong>: <strong>£${finalPaymentAmount.toFixed(2)}</strong></li>`;
}
}

// Display results
const result = `
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>.
Balance transfer will need to be renewed at least <strong>${Math.round(totalTimeToPay / balanceTransferDuration)} times</strong>.
Balance transfer will need to be renewed at least <strong>${Math.round(totalTimeToPay / balanceTransferDuration)} times</strong>.<br><br>
<strong>Breakdown</strong>:<br><br>
${breakdownString}
`;
document.getElementById("result").innerHTML = result;
}
Expand Down

0 comments on commit 4d68b81

Please sign in to comment.