Best Loan Calculator

Best Loan Calculator

function calculateBestLoan() { const loanAmount = parseFloat(document.getElementById(‘loanAmount’).value); const interestRate = parseFloat(document.getElementById(‘interestRate’).value) / 100; const loanTerm = parseFloat(document.getElementById(‘loanTerm’).value); if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || loanAmount <= 0 || interestRate <= 0 || loanTerm <= 0) { alert("Please enter valid positive values for all fields."); return; } const numberOfPayments = loanTerm * 12; const monthlyInterestRate = interestRate / 12; const monthlyPayment = loanAmount * monthlyInterestRate / (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)); document.getElementById('monthlyPayment').value = monthlyPayment.toFixed(2); }

Leave a Reply

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