- 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;
};
var calculateFlights = function (distance, isBusinessClass) {
var miles = calculateMiles(distance, isBusinessClass);
console.log('Miles for the flight: ' + miles);
};
calculateFlights(3118, true);
Result
Goalscompleted
- Create third parameter
milesTarget
incalculateFlights
function and transfer third argument15000
in the call ofcalculateFlights
function. - Inside
calculateFlights
function, after logging miles in the console, declare variableflights
, which equalsmilesTarget / miles
. - Log the number of flights in the console
'Number of flights:' + flights
. - Round the number of flights up
Math.ceil(milesTarget / miles)
.
Comments