- script.js
JavaScript
var calculateMiles = function (distance, isBusinessClass) {
var percent = 0.18;
if (isBusinessClass) {
percent += 0.04;
}
if (distance > 3500) {
percent += 0.15;
}
return distance * percent;
};
Result
Goalscompleted
- After the
calculateMilesfunction, declare functioncalculateFlightswith two parametersdistanceandisBusinessClass. - Inside the new function, declare variable
miles, which is equal to the result of functioncalculateMiles(distance, isBusinessClass). - Then log in the console the value of variable
'Miles per flight: ' + miles. - Below, after declaring all functions, call function
calculateFlights(3118, true);.
Comments