function calculateLoan() {
const loanAmount = parseFloat(document.getElementById("loan-amount").value);
const interestRate = parseFloat(document.getElementById("interest-rate").value);
const loanTerm = parseFloat(document.getElementById("loan-term").value) * 12; // convert to months const monthlyInterestRate = (interestRate / 100) / 12;
const monthlyPayment = (loanAmount * monthlyInterestRate) / (1 - Math.pow(1 + monthlyInterestRate, -loanTerm)); const monthlyPaymentElement = document.getElementById("monthly-payment");
monthlyPaymentElement.value = monthlyPayment.toFixed(2);
}
Skip to content