diff --git a/fuel-calc.html b/fuel-calc.html deleted file mode 100644 index 1520638..0000000 --- a/fuel-calc.html +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - Is Diesel Cheaper? - - - - -
-
- -
-
- - - -
-
- -
- -
-
-
- -
- - -
-
- - -
-
- - -
- - -
- - -
-
- - -
-
- - -
-
- -
- - -
- -
- To offset the tax difference at 17500 km/year, - a petrol car would need to consume at least 0.00L/100km, - or the diesel price should be at least 0.00 €/L. -
- - - - - - - - - - - - - -
Annual DistanceDiesel TotalPetrol TotalDifference
-
- - - - - - diff --git a/fuel-calc.js b/fuel-calc.js new file mode 100644 index 0000000..bb8c610 --- /dev/null +++ b/fuel-calc.js @@ -0,0 +1,98 @@ +let currentLang = 'ru'; + + +function updateLanguage() { + const language = langData[currentLang]; + + document.getElementById("header").textContent = language.header; + document.getElementById("dTaxLabel").textContent = language.dTaxLabel; + document.getElementById("dPriceLabel").textContent = language.dPriceLabel; + document.getElementById("dConsLabel").textContent = language.dConsLabel; + document.getElementById("pTaxLabel").textContent = language.pTaxLabel; + document.getElementById("pPriceLabel").textContent = language.pPriceLabel; + document.getElementById("pConsLabel").textContent = language.pConsLabel; + document.getElementById("annualKmLabel").textContent = language.annualKmLabel; + document.getElementById("resultText1").textContent = language.resultText1; + document.getElementById("resultText2").textContent = language.resultText2; + document.getElementById("resultText3").textContent = language.resultText3; + document.getElementById("resultText4").textContent = language.resultText4; + document.getElementById("tableDistance").textContent = language.tableDistance; + document.getElementById("tableDieselTotal").textContent = language.tableDieselTotal; + document.getElementById("tablePetrolTotal").textContent = language.tablePetrolTotal; + document.getElementById("tableDifference").textContent = language.tableDifference; + + calculate(); +} + + +document.querySelector('#language-toggle').addEventListener('click', () => { + currentLang = (currentLang === 'en') ? 'ru' : 'en'; + updateLanguage(); +}); + +document.querySelector('#dark-mode-toggle').addEventListener('click', () => { + document.body.classList.toggle('dark-mode'); +}); + +function calculate() { + const dTax = parseFloat(document.getElementById("dTax").value); + const dPrice = parseFloat(document.getElementById("dPrice").value); + const dCons = parseFloat(document.getElementById("dCons").value); + const pTax = parseFloat(document.getElementById("pTax").value); + const pPrice = parseFloat(document.getElementById("pPrice").value); + const pCons = parseFloat(document.getElementById("pCons").value); + const annualKm = parseFloat(document.getElementById("annualKm").value); + + const dieselCostPerKm = (dPrice * dCons) / 100; + const petrolCostPerKm = (pPrice * pCons) / 100; + + const dieselAnnualCost = (dTax + (dieselCostPerKm * annualKm)); + const petrolAnnualCost = (pTax + (petrolCostPerKm * annualKm)); + + const diff = Math.abs(dieselAnnualCost - petrolAnnualCost); + + let breakEvenCons = 0; + if (dCons < pCons || dTax > pTax) { + breakEvenCons = (pCons - ((dTax - pTax) / (annualKm * (pPrice - dPrice)))); + if (breakEvenCons <= 0) breakEvenCons = 0; + } + + let minDieselPrice = 0; + if (dPrice < pPrice || dTax > pTax) { + minDieselPrice = (pPrice - ((dTax - pTax) / (annualKm * (pCons - dCons)))); + if (minDieselPrice <= 0) minDieselPrice = 0; + } + + document.getElementById("displayKm").textContent = annualKm.toLocaleString(); + document.getElementById("breakEvenCons").textContent = breakEvenCons.toFixed(2); + document.getElementById("minDieselPrice").textContent = minDieselPrice.toFixed(2); + + const tbody = document.getElementById("comparisonTable").getElementsByTagName('tbody')[0]; + tbody.innerHTML = ''; + + for (let i = 10000; i <= 50000; i += 5000) { + const row = tbody.insertRow(); + const cell1 = row.insertCell(0); + const cell2 = row.insertCell(1); + const cell3 = row.insertCell(2); + const cell4 = row.insertCell(3); + + const dCost = (dTax + ((dPrice * dCons) / 100 * i)).toFixed(2); + const pCost = (pTax + ((pPrice * pCons) / 100 * i)).toFixed(2); + const diffCost = (parseFloat(pCost) - parseFloat(dCost)).toFixed(2); + + cell1.innerHTML = "" + i.toLocaleString() + ""; + cell2.innerHTML = dCost + " €"; + cell3.innerHTML = pCost + " €"; + cell4.innerHTML = diffCost + " €"; + + if (diffCost > 0) { + cell4.className = "saving"; + } else { + cell4.className = "loss"; + } + } +} + +calculate(); +updateLanguage(); diff --git a/index.html b/index.html new file mode 100644 index 0000000..272c20c --- /dev/null +++ b/index.html @@ -0,0 +1,87 @@ + + + + + + Is Diesel Cheaper? + + + + +
+
+ +
+
+ + + +
+
+ +
+ +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+ To offset the tax difference at 17500 km/year, + a petrol car would need to consume at least 0.00L/100km, + or the diesel price should be at least 0.00 €/L. +
+ + + + + + + + + + + + + +
Annual DistanceDiesel TotalPetrol TotalDifference
+
+ + + + + + + diff --git a/languages.js b/languages.js new file mode 100644 index 0000000..48d2814 --- /dev/null +++ b/languages.js @@ -0,0 +1,40 @@ +const langData = { + en: { + header: "Car Cost Comparison", + dTaxLabel: "Diesel Annual Tax (€)", + dPriceLabel: "Diesel Price per Liter (€)", + dConsLabel: "Diesel Consumption (L/100km)", + pTaxLabel: "Petrol Annual Tax (€)", + pPriceLabel: "Petrol Price per Liter (€)", + pConsLabel: "Petrol Consumption (L/100km)", + annualKmLabel: "Your Annual Distance (km)", + resultText1: "To offset the tax difference at ", + resultText2: "km/year, a petrol car would need to consume at least ", + resultText3: " L/100km, or the diesel price should be at least ", + resultText4: "€/L.", + tableDistance: "Annual Distance", + tableDieselTotal: "Diesel Total", + tablePetrolTotal: "Petrol Total", + tableDifference: "Difference" + }, + + ru: { + header: "Сравнение затрат на автомобили", + dTaxLabel: "Годовая плата за дизель (€)", + dPriceLabel: "Цена дизеля за литр (€)", + dConsLabel: "Расход дизеля (л/100 км)", + pTaxLabel: "Годовая плата за бензин (€)", + pPriceLabel: "Цена бензина за литр (€)", + pConsLabel: "Расход бензина (л/100 км)", + annualKmLabel: "Ваш ежегодный пробег (км)", + resultText1: "Чтобы компенсировать разницу в налогах при ", + resultText2: " км в год, расход бензинового автомобиля должен быть не менее ", + resultText3: " л/100 км, либо цена дизеля должна быть не менее ", + resultText4: " €/л.", + tableDistance: "Ежегодная дистанция", + tableDieselTotal: "Общие затраты на дизель", + tablePetrolTotal: "Общие затраты на бензин", + tableDifference: "Разница" + } +}; + diff --git a/languages.json b/languages.json deleted file mode 100644 index 69d1674..0000000 --- a/languages.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "en": { - "header": "Car Cost Comparison", - "dTaxLabel": "Diesel Annual Tax (€)", - "dPriceLabel": "Diesel Price per Liter (€)", - "dConsLabel": "Diesel Consumption (L/100km)", - "pTaxLabel": "Petrol Annual Tax (€)", - "pPriceLabel": "Petrol Price per Liter (€)", - "pConsLabel": "Petrol Consumption (L/100km)", - "annualKmLabel": "Your Annual Distance (km) for Break-even", - "resultText": "To offset the tax difference at ", - "tableDistance": "Annual Distance", - "tableDieselTotal": "Diesel Total", - "tablePetrolTotal": "Petrol Total", - "tableDifference": "Difference" - }, - "ru": { - "header": "Сравнение затрат на автомобили", - "dTaxLabel": "Годовая плата за дизель (€)", - "dPriceLabel": "Цена дизеля за литр (€)", - "dConsLabel": "Расход дизеля (л/100км)", - "pTaxLabel": "Годовая плата за бензин (€)", - "pPriceLabel": "Цена бензина за литр (€)", - "pConsLabel": "Расход бензина (л/100км)", - "annualKmLabel": "Ваша ежегодная дистанция (км) для компенсации", - "resultText": "Чтобы компенсировать разницу в налогах при ", - "tableDistance": "Ежегодная дистанция", - "tableDieselTotal": "Итоговый расход дизеля", - "tablePetrolTotal": "Итоговый расход бензина", - "tableDifference": "Разница" - } -} \ No newline at end of file diff --git a/style.css b/style.css index eff6ebb..ae071d6 100644 --- a/style.css +++ b/style.css @@ -141,5 +141,5 @@ th { .button-toggle svg { width: 100%; height: 100%; - color: var(--text-color); + fill: var(--text-color); }