Changed around line 1
+ function formatCurrency(amount) {
+ return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(Math.round(amount));
+ }
+
+ function calculateLoan() {
+ const propertyPrice = parseFloat(document.getElementById('propertyPrice').value);
+ const downPayment = parseFloat(document.getElementById('downPayment').value);
+ const loanDuration = parseFloat(document.getElementById('loanDuration').value);
+ const interestRates = document.getElementById('interestRates').value.split(',').map(Number);
+ const renovationCost = parseFloat(document.getElementById('renovationCost').value) || 0;
+
+ const notaryFees = propertyPrice * 0.08;
+ const loanAmount = propertyPrice + renovationCost + notaryFees - downPayment;
+
+ const results = interestRates.map(rate => {
+ const monthlyRate = rate / 100 / 12;
+ const numberOfPayments = loanDuration * 12;
+ const monthlyPayment = loanAmount * monthlyRate / (1 - Math.pow(1 + monthlyRate, -numberOfPayments));
+ const totalCost = monthlyPayment * numberOfPayments;
+ const interestCost = totalCost - loanAmount;
+
+ return {
+ rate,
+ monthlyPayment,
+ totalCost,
+ interestCost
+ };
+ });
+
+ displayResults(results[0], loanAmount, notaryFees);
+ displayComparisonTable(results);
+ }
+
+ function displayResults(result, loanAmount, notaryFees) {
+ document.getElementById('loanAmount').textContent = formatCurrency(loanAmount);
+ document.getElementById('notaryFees').textContent = formatCurrency(notaryFees);
+ document.getElementById('monthlyPayment').textContent = formatCurrency(result.monthlyPayment);
+ document.getElementById('totalCost').textContent = formatCurrency(result.totalCost);
+ document.getElementById('interestCost').textContent = formatCurrency(result.interestCost);
+ }
+
+ function displayComparisonTable(results) {
+ const tableBody = document.querySelector('#comparisonTable tbody');
+ tableBody.innerHTML = results.map(result => `
+
+
${result.rate}% | +
${formatCurrency(result.monthlyPayment)} | +
${formatCurrency(result.totalCost)} | +
${formatCurrency(result.interestCost)} | +
+ `).join('');
+ }
+
+ document.getElementById('creditForm').addEventListener('submit', function(e) {
+ e.preventDefault();
+ calculateLoan();
+ });