Mortgage Payment Results:
Monthly Payment: $
Estimated Property Tax: $
Estimated Insurance: $
function calculateMortgage() {
const loanAmount = parseFloat(document.getElementById(‘loanAmount’).value);
const interestRate = parseFloat(document.getElementById(‘interestRate’).value) / 100 / 12;
const loanTerm = parseInt(document.getElementById(‘loanTerm’).value) * 12;
const propertyTax = parseFloat(document.getElementById(‘propertyTax’).value) / 12;
const homeInsurance = parseFloat(document.getElementById(‘homeInsurance’).value) / 12;
if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(propertyTax) || isNaN(homeInsurance)) {
alert(‘Please fill out all fields with valid numbers’);
return;
}
// Mortgage Payment Calculation
const monthlyPayment = (loanAmount * interestRate) / (1 – Math.pow(1 + interestRate, -loanTerm));
// Display results
document.getElementById(‘monthlyPayment’).innerText = monthlyPayment.toFixed(2);
document.getElementById(‘estimatedTax’).innerText = propertyTax.toFixed(2);
document.getElementById(‘estimatedInsurance’).innerText = homeInsurance.toFixed(2);
document.getElementById(‘mortgageResults’).style.display = ‘block’;
}
function resetCalculator() {
document.getElementById(‘mortgage-calculator-form’).reset();
document.getElementById(‘mortgageResults’).style.display = ‘none’;
}