function calculateLoan() {
const loanAmount = parseFloat(document.getElementById(“loanAmount”).value);
const interestRate = parseFloat(document.getElementById(“interestRate”).value) / 100;
const loanTerm = parseFloat(document.getElementById(“loanTerm”).value);
const balloonPayment = parseFloat(document.getElementById(“balloonPayment”).value);
if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(balloonPayment)) {
alert(“Please fill in all fields with valid values.”);
return;
}
const monthlyRate = interestRate / 12;
const numberOfPayments = loanTerm * 12;
// Calculate monthly payment for interest only
const monthlyPayment = (loanAmount * monthlyRate);
const totalInterest = (monthlyPayment * numberOfPayments) – loanAmount;
// Set the calculated values
document.getElementById(“monthlyPayment”).value = monthlyPayment.toFixed(2);
document.getElementById(“totalInterest”).value = totalInterest.toFixed(2);
const details = `
Loan Amount: $${loanAmount.toFixed(2)}
Interest Rate: ${(interestRate * 100).toFixed(2)}%
Loan Term: ${loanTerm} years
Balloon Payment: $${balloonPayment.toFixed(2)}
Monthly Payment (Interest Only): $${monthlyPayment.toFixed(2)}
Total Interest: $${totalInterest.toFixed(2)}
`;
document.getElementById(“details”).innerHTML = details;
document.getElementById(“calculationDetails”).style.display = “block”;
}