Loan Details
Monthly Payment:
Total Interest:
Total Amount Payable:
function calculateCarLoan() {
const loanAmount = parseFloat(document.getElementById(‘loanAmount’).value);
const loanTerm = parseInt(document.getElementById(‘loanTerm’).value);
const interestRate = parseFloat(document.getElementById(‘interestRate’).value) / 100;
const monthlyIncome = parseFloat(document.getElementById(‘monthlyIncome’).value);
const downPayment = parseFloat(document.getElementById(‘downPayment’).value);
if (isNaN(loanAmount) || isNaN(loanTerm) || isNaN(interestRate) || isNaN(monthlyIncome) || isNaN(downPayment)) {
alert(“Please fill in all fields correctly.”);
return;
}
const principal = loanAmount – downPayment;
const numberOfPayments = loanTerm * 12;
const monthlyInterestRate = interestRate / 12;
const monthlyPayment = (principal * monthlyInterestRate) / (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments));
const totalInterest = (monthlyPayment * numberOfPayments) – principal;
const totalAmount = principal + totalInterest;
document.getElementById(‘monthlyPayment’).textContent = `₱${monthlyPayment.toFixed(2)}`;
document.getElementById(‘totalInterest’).textContent = `₱${totalInterest.toFixed(2)}`;
document.getElementById(‘totalAmount’).textContent = `₱${totalAmount.toFixed(2)}`;
document.getElementById(‘loanResults’).style.display = ‘block’;
}