-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (15 loc) · 847 Bytes
/
script.js
File metadata and controls
19 lines (15 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function calculateLoan() {
let loanAmountValue = parseFloat(document.getElementById("loan-amount").value);
let interestRateValue = parseFloat(document.getElementById("interest-rate").value);
let monthsToPayValue = parseInt(document.getElementById("months-to-pay").value);
console.log(loanAmountValue);
console.log(interestRateValue);
console.log(monthsToPayValue);
if (isNaN(loanAmountValue) || isNaN(interestRateValue) || isNaN(monthsToPayValue) || monthsToPayValue <= 0) {
document.getElementById("payment").innerHTML = "Please enter valid values";
return;
}
let interest = (loanAmountValue * interestRateValue * 0.01) / monthsToPayValue;
let monthlyPayment = (loanAmountValue / monthsToPayValue + interest).toFixed(2);
document.getElementById("payment").innerHTML = `Monthly Payment: ${monthlyPayment} €`;
}