Interest Mortgage Rate Calculator Bankrate

Interest Mortgage Rate Calculator

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; if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || loanAmount <= 0 || interestRate <= 0 || loanTerm <= 0) { alert('Please fill all fields with valid numbers.'); return; } const monthlyPayment = (loanAmount * interestRate) / (1 – Math.pow(1 + interestRate, -loanTerm)); const totalPayment = monthlyPayment * loanTerm; const totalInterest = totalPayment – loanAmount; document.getElementById('monthlyPayment').value = monthlyPayment.toFixed(2); document.getElementById('totalPayment').value = totalPayment.toFixed(2); document.getElementById('totalInterest').value = totalInterest.toFixed(2); document.getElementById('calculationSteps').innerHTML = `

Calculation Steps:

Loan Amount: $${loanAmount.toFixed(2)}

Interest Rate: ${interestRate * 12 * 100}% annually

Loan Term: ${loanTerm / 12} years

Monthly Payment: $${monthlyPayment.toFixed(2)}

Total Payment: $${totalPayment.toFixed(2)}

Total Interest: $${totalInterest.toFixed(2)}

`; }

Leave a Reply

Your email address will not be published. Required fields are marked *