-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc2.js
21 lines (16 loc) · 1.27 KB
/
calc2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
document.getElementById("loanForm2").addEventListener("submit", function(event) {
event.preventDefault();
var loanAmount = parseFloat(document.getElementById("loanAmount").value.replace(/\D/g, ''));
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value.replace(",", ".")); // Заменяем запятую на точку для точности вычислений
var loanTermYears = parseInt(document.getElementById("loanTerm").value);
if (isNaN(loanAmount) || isNaN(annualInterestRate) || isNaN(loanTermYears) || loanAmount <= 0 || annualInterestRate <= 0 || loanTermYears <= 0) {
alert("Пожалуйста, введите корректные данные.");
return;
}
var monthlyInterestRate = annualInterestRate / 100 / 12;
var loanTermMonths = loanTermYears * 12;
// Рассчитываем ежемесячный платеж
var monthlyPayment = (loanAmount * monthlyInterestRate) / (1 - Math.pow(1 + monthlyInterestRate, -loanTermMonths));
// Выводим результат на страницу
document.getElementById("monthlyPayment").innerText = "Ежемесячный платеж: " + monthlyPayment.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, " ") + " тенге";
});