You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (!amountToTransfer ||!balanceTransferFee ||!balanceTransferDuration ||!plannedMonthlyPayment) {
15
16
document.getElementById("result").innerHTML="<strong style='color: red;'>Please fill in all fields.</strong>";
16
17
return; // Exit the function if validation fails
17
18
}
19
+
18
20
// Initialise Variables
19
21
let totalTimeToPay =0;
20
22
let feePaid =0;
21
23
constinitialAmountToTransfer= amountToTransfer;
24
+
let counter =0;
25
+
let breakdownString ="";
22
26
23
27
while (amountToTransfer > plannedMonthlyPayment) {
28
+
counter +=1;
24
29
let amountTransferred = amountToTransfer * (1+ balanceTransferFee /100);
25
30
let totalTimeRequired = amountTransferred / plannedMonthlyPayment;
26
31
27
32
if (totalTimeRequired > balanceTransferDuration) {
33
+
breakdownString +=`<li> Amount to balance transfer in <strong>Year ${counter}</strong> with fee included: <strong>£${amountTransferred.toFixed(2)}</strong></li>`;
let finalPaymentAmountWithFee = plannedMonthlyPayment * totalTimeRequired;
41
+
breakdownString +=`<li> Amount to balance transfer in <strong>Year ${counter}</strong> with fee included: <strong>£${finalPaymentAmountWithFee.toFixed(2)}</strong></li>`;
42
+
let finalPaymentAmount = finalPaymentAmountWithFee *0.65;
43
+
breakdownString +=`<li> Amount to finish by one time payment in <strong>Year ${counter}</strong>: <strong>£${finalPaymentAmount.toFixed(2)}</strong></li>`;
34
44
}
35
45
}
36
46
37
47
// Display results
38
48
constresult=`
39
49
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
50
41
-
Balance transfer will need to be renewed at least <strong>${Math.round(totalTimeToPay / balanceTransferDuration)} times</strong>.
51
+
Balance transfer will need to be renewed at least <strong>${Math.round(totalTimeToPay / balanceTransferDuration)} times</strong>.<br><br>
0 commit comments