function calculateCarPayment() {
const carPrice = parseInt(document.getElementById("car-price").value);
const downPayment = parseInt(document.getElementById("down-payment").value);
const loanTerm = parseInt(document.getElementById("loan-term").value);
const interestRate = parseInt(document.getElementById("interest-rate").value);
const loanAmount = carPrice - downPayment;
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