Calculation Steps
1. Input the loan amount, term, and interest rate.
2. Use the formula for monthly payments: PMT = P [r(1 + r)^n] / [(1 + r)^n – 1] where:
- P = Loan amount
- r = Monthly interest rate (annual rate divided by 12)
- n = Total number of payments (loan term in years multiplied by 12)
function calculateLoan() {
const loanAmount = parseFloat(document.getElementById(“loanAmount”).value);
const loanTerm = parseFloat(document.getElementById(“loanTerm”).value);
const interestRate = parseFloat(document.getElementById(“interestRate”).value);
if (isNaN(loanAmount) || isNaN(loanTerm) || isNaN(interestRate) || loanAmount <= 0 || loanTerm <= 0 || interestRate <= 0) {
alert("Please enter valid positive values for all fields.");
return;
}
const monthlyInterestRate = interestRate / 100 / 12;
const totalPayments = loanTerm * 12;
const monthlyPayment = loanAmount * (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, totalPayments)) / (Math.pow(1 + monthlyInterestRate, totalPayments) – 1);
document.getElementById("monthlyPayment").value = monthlyPayment.toFixed(2);
}
function resetCalculator() {
document.getElementById("cibcLoanCalculator").reset();
}
function toggleSteps() {
const steps = document.getElementById("calculationSteps");
steps.style.display = steps.style.display === "none" ? "block" : "none";
}