- script.js
JavaScript
var calculateMiles = function (distance, isBusinessClass) {
if (isBusinessClass) {
return distance * 0.22;
}
return distance * 0.18;
};
var milesEconom = calculateMiles(3000, false);
var milesBusiness = calculateMiles(3000, true);
console.log('With economy class from MuffAir, you’ll get ' + milesEconom + ' miles');
console.log('With business class of MuffAir, you’ll save ' + milesBusiness + ' miles');
Result
Goalscompleted
- In the body of the function, it the very beginning, create variable
percent
equal to0.18
on the 2nd line. - Inside the condition, instead of calculating miles, increase variable
percent
by0.04
. - Replace the expression that the function returns with
distance * percent
.
Comments