Mortgage Calculator
* {
box-sizing: border-box;
font-family: Arial, sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
h1 {
text-align: center;
}
.form-group {
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="number"] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #3e8e41;
}
.result {
margin-top: 20px;
}
h2 {
margin-bottom: 10px;
}
p {
font-size: 24px;
}
function calculate() {
// get user inputs
var loanAmount = document.getElementById("loan-amount").value;
var interestRate = document.getElementById("interest-rate").value;
var loanTerm = document.getElementById("loan-term").value;
// convert interest rate to monthly percentage and loan term to months
var monthlyRate = interestRate / 1200;
var loanTermMonths = loanTerm * 12;
// calculate monthly payment
var monthlyPayment = (loanAmount * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -loanTermMonths));
// display monthly payment
document.getElementById("monthly-payment").innerHTML = "$" + monthlyPayment.toFixed(2);
}