Simple Loan Calculator Uk

Simple Loan Calculator

function calculateLoan() { const amount = parseFloat(document.getElementById(‘loanAmount’).value); const rate = parseFloat(document.getElementById(‘interestRate’).value) / 100 / 12; const term = parseFloat(document.getElementById(‘loanTerm’).value) * 12; if (!isNaN(amount) && !isNaN(rate) && !isNaN(term) && amount > 0 && rate > 0 && term > 0) { const monthlyPayment = (amount * rate) / (1 – Math.pow(1 + rate, -term)); const totalRepayment = monthlyPayment * term; document.getElementById(‘monthlyPayment’).value = monthlyPayment.toFixed(2); document.getElementById(‘totalRepayment’).value = totalRepayment.toFixed(2); } else { alert(“Please enter valid positive values.”); } } function resetLoan() { document.getElementById(‘loanAmount’).value = ”; document.getElementById(‘interestRate’).value = ”; document.getElementById(‘loanTerm’).value = ”; document.getElementById(‘monthlyPayment’).value = ”; document.getElementById(‘totalRepayment’).value = ”; }

Leave a Reply

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