function calculateCarPayment() {
const carPrice = parseFloat(document.getElementById(“carPrice”).value);
const downPayment = parseFloat(document.getElementById(“downPayment”).value);
const interestRate = parseFloat(document.getElementById(“interestRate”).value) / 100 / 12;
const loanTerm = parseInt(document.getElementById(“loanTerm”).value) * 12;
if (isNaN(carPrice) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm)) {
alert(“Please fill in all fields correctly.”);
return;
}
const loanAmount = carPrice – downPayment;
const monthlyPayment = (loanAmount * interestRate) / (1 – Math.pow(1 + interestRate, -loanTerm));
document.getElementById(“monthlyPayment”).textContent = “$” + monthlyPayment.toFixed(2);
}