- 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, milesTarget) {
var miles = calculateMiles(distance, isBusinessClass);
var flights = Math.ceil(milesTarget / miles);
return flights;
};
console.log('Required number of flights in business class to Valencia: ' + calculateFlights(3118, true, 15000));
console.log('Required number of economy flights to Lisbon: ' + calculateFlights(3617, false, 15000));
Result
Goalscompleted
- Below, after declaring the flight calculation function, write
calculateFlights(3118, true, 15000)
in the new variableflightsVariant1
. - When logging the message, replace
calculateFlights(3118, true, 15000)
withflightsVariant1
. - Write the result of calling the function
calculateFlights(3617, false, 15000)
in variableflightsVariant2
. - When logging the message, replace
calculateFlights(3617, false, 15000)
withflightsVariant2
.
Comments