Homeloan Extra Payment Calc

by Florian Bar

JavaScript

const ASSURANCE_PREMIUM = 1700;
const SERVICE_FEE = 69;
const INSURANCE_PREMIUM = 408;
const INTEREST_RATE = 7.5;
const MONTHLY_REPAYMENT = 11300;

let currentBondDebt = 1002900;
let extraPayment = 9000;
let annualIncrease = 2000;
let annualBonus = 10000;
let paymentCount = 2;
let year = 2022;

while (currentBondDebt >= 0) {
	if (paymentCount !== 0 && paymentCount % 12 === 0) {
    extraPayment += annualIncrease;
    currentBondDebt -= annualBonus;
    year++;
    console.log(year, "R " + parseInt(currentBondDebt));
  }
  paymentCount++;
  
	const monthlyInterest = (INTEREST_RATE / 100 / 12) * currentBondDebt;
	const payment = MONTHLY_REPAYMENT - ASSURANCE_PREMIUM - SERVICE_FEE - INSURANCE_PREMIUM - monthlyInterest / 2;
  
  currentBondDebt -= payment;
  currentBondDebt -= extraPayment;
}

const years = parseInt(paymentCount / 12);
const months = paymentCount % 12;
console.log(`${years} years ${months} months`);