-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (19 loc) · 884 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var headerResults = document.getElementById("totalFuelNeeded");
var btnCalculate = document.getElementById("btnCalculate");
// Event listener on click of the button
btnCalculate.onclick = function(){
var txtRaceDuration = parseFloat(document.getElementById("raceDuration").value);
var txtAvgLapTime = parseFloat(document.getElementById("avgLapTime").value);
var txtfuelPerLap = parseFloat(document.getElementById("fuelPerLap").value);
//console.log(txtRaceDuration);
calculateFuel(txtRaceDuration, txtAvgLapTime, txtfuelPerLap);
}
function calculateFuel(raceDuration, avgLapTime, fuelPerLap) {
var lapsLeft = raceDuration / avgLapTime;
var fuelTotal = Number.parseFloat(lapsLeft * fuelPerLap).toFixed(2);
console.log(fuelTotal);
updateResult(fuelTotal);
}
function updateResult(totalLiters){
headerResults.innerHTML = totalLiters;
}