Changed around line 1
+ document.getElementById('creditForm').addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const montantBien = parseFloat(document.getElementById('montantBien').value);
+ const apport = parseFloat(document.getElementById('apport').value);
+ const taux = parseFloat(document.getElementById('taux').value) / 100;
+ const coutTravaux = parseFloat(document.getElementById('coutTravaux').value);
+ const duree = parseInt(document.getElementById('duree').value);
+
+ const montantPret = montantBien + coutTravaux - apport;
+ const fraisNotaire = montantBien * 0.08;
+ const mensualites = calculateMonthlyPayment(montantPret, taux, duree);
+ const coutTotal = mensualites * duree * 12;
+ const coutInterets = coutTotal - montantPret;
+ const fraisAnnexes = fraisNotaire + coutTravaux;
+
+ document.getElementById('montantPret').textContent = montantPret.toFixed(2);
+ document.getElementById('fraisNotaire').textContent = fraisNotaire.toFixed(2);
+ document.getElementById('mensualites').textContent = mensualites.toFixed(2);
+ document.getElementById('coutTotal').textContent = coutTotal.toFixed(2);
+ document.getElementById('coutInterets').textContent = coutInterets.toFixed(2);
+ document.getElementById('fraisAnnexes').textContent = fraisAnnexes.toFixed(2);
+
+ document.getElementById('results').classList.remove('hidden');
+ });
+
+ function calculateMonthlyPayment(amount, rate, years) {
+ const monthlyRate = rate / 12;
+ const numberOfPayments = years * 12;
+ return amount * monthlyRate / (1 - Math.pow(1 + monthlyRate, -numberOfPayments));
+ }