diff --git a/fuel-calc.html b/fuel-calc.html
index 940dc27..a18ef98 100644
--- a/fuel-calc.html
+++ b/fuel-calc.html
@@ -48,7 +48,8 @@
To offset the tax difference at 17500 km/year,
- a petrol car would need to consume at least 0.00 L/100km.
+ a petrol car would need to consume at least 0.00 L/100km,
+ or the diesel price should be at least 0.00 €/L.
diff --git a/script.js b/script.js
index 67bab48..0e40b67 100644
--- a/script.js
+++ b/script.js
@@ -18,7 +18,22 @@ function calculate() {
document.getElementById('displayKm').innerText = annualKm.toLocaleString();
document.getElementById('breakEvenCons').innerText = isFinite(breakEven) ? breakEven.toFixed(2) : "0.00";
- // 2. Generate Table
+ // 2. Calculate Minimum Diesel Price where user's pCons equals break-even consumption
+ // We want to solve for dPrice such that: pCons = (100 * taxDiff / (annualKm * pPrice)) + (dCons * dPrice / pPrice)
+ // Rearranging for dPrice:
+ // pCons - (100 * taxDiff / (annualKm * pPrice)) = (dCons * dPrice / pPrice)
+ // dPrice = (pCons - (100 * taxDiff / (annualKm * pPrice))) * pPrice / dCons
+
+ let minDieselPrice = 0;
+ if (dCons > 0 && annualKm > 0 && pPrice > 0) {
+ const firstTerm = 100 * taxDiff / (annualKm * pPrice);
+ const secondTerm = pCons - firstTerm;
+ minDieselPrice = secondTerm * pPrice / dCons;
+ }
+
+ document.getElementById('minDieselPrice').innerText = isFinite(minDieselPrice) ? minDieselPrice.toFixed(2) : "0.00";
+
+ // 3. Generate Table
const distances = [5000, 10000, 15000, 20000, 25000, 30000];
const tbody = document.querySelector('#comparisonTable tbody');
tbody.innerHTML = '';