סך כל התשלומים: ${totalPayment.toFixed(2)} ש"ח
סך כל הריבית: ${totalInterest.toFixed(2)} ש"ח
יחס החזר להכנסה: ${debtToIncomeRatio.toFixed(2)}%
`;
document.getElementById('result').innerHTML = resultHtml;
// השוואה בין מסלולים
const comparisonHtml = `
השוואה בין מסלולים:
ריבית קבועה: ${calculateMonthlyPayment('fixed').toFixed(2)} ש"ח לחודש
ריבית משתנה: ${calculateMonthlyPayment('variable').toFixed(2)} ש"ח לחודש
`;
document.getElementById('comparison').innerHTML = comparisonHtml;
});
function calculateMonthlyPayment(type) {
const loanAmount = parseFloat(document.getElementById('loanAmount').value);
const annualInterestRate = parseFloat(document.getElementById('interestRate').value) / 100;
const loanTerm = parseInt(document.getElementById('loanTerm').value);
const monthlyInterestRate = annualInterestRate / 12;
const numberOfPayments = loanTerm * 12;
if (type === 'fixed') {
return (loanAmount * monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments)) / (Math.pow(1 + monthlyInterestRate, numberOfPayments) - 1);
} else {
return loanAmount / numberOfPayments + (loanAmount * monthlyInterestRate);
}
}