Estimated Monthly Payment:
£0.00
function calculateMortgage() {
const loanAmount = parseFloat(document.getElementById(“loan-amount”).value);
const interestRate = parseFloat(document.getElementById(“interest-rate”).value) / 100 / 12;
const loanTerm = parseFloat(document.getElementById(“loan-term”).value) * 12;
if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm)) {
alert(“Please enter valid values for all fields.”);
return;
}
const monthlyPayment = (loanAmount * interestRate) / (1 – Math.pow(1 + interestRate, -loanTerm));
document.getElementById(“monthly-payment”).innerText = “£” + monthlyPayment.toFixed(2);
}
function resetCalculator() {
document.getElementById(“loan-amount”).value = “”;
document.getElementById(“interest-rate”).value = “”;
document.getElementById(“loan-term”).value = “”;
document.getElementById(“monthly-payment”).innerText = “£0.00”;
}