Interactive online courses HTML Academy
2026-03-09 14:13 Diff
  • 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; }; var flightsVariantFirst = calculateFlights(3118, true, 15000); var flightsVariantSecond = calculateFlights(3617, false, 15000); console.log('Required number of flights in business class to Valencia: ' + flightsVariantFirst); console.log('Required number of economy flights to Lisbon: ' + flightsVariantSecond);

Thanks! We’ll fix everything at once!

Result

  1. At the end of the program, add a check to make sure that flightsVariant1 is greater than flightsVariant2.
  2. If the check is successful, log the following message in the console 'You will save quicker flying economy to Lisbon! Number of flights: ' + flightsVariant2.
  3. Otherwise, log the message 'You will save quicker flying business class to Valencia! Number of flights: ' + flightsVariant1.