function calculateTotalMortgage(percent, contribution, amount, countMonths) {
if (percent <= 0 || contribution < 0 || amount <= 0 || countMonths <= 0) {
throw new Error("Invalid input values");
}
const monthlyRate = (percent / 100) / 12; // месячная ставка
const loanBody = amount - contribution; // тело кредита
const monthlyPayment = loanBody * (monthlyRate + (monthlyRate / (Math.pow(1 + monthlyRate, countMonths) - 1))); // ежемесячный платеж
const totalPayment = (monthlyPayment * countMonths).toFixed(2); // общая сумма платежей
return Number(totalPayment);
}
// Пример вызова
console.log(calculateTotalMortgage(5, 200000, 1000000, 60)); // Введите свои данные