add min d price
This commit is contained in:
17
script.js
17
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 = '';
|
||||
|
||||
Reference in New Issue
Block a user