HTML Academy
I see the target
Functions18/24
Back to the list of tasks
  • 1. Fasten your seat belts
  • 2. Long-distance flight
  • 3. Going the second circle
  • 4. Helper function
  • 5. Function, I’m calling you!
  • 6. I have a parameter for you
  • 7. Order of parameters
  • 8. Return from function
  • 9. Summary of “Functions”. Part 1
  • 10. Seventh program: “From salary to salary”
  • 11. Business trip
  • 12. Write, simplify
  • 13. Get rid of unnecessary
  • 14. Make me beautiful
  • 15. Just add percentage
  • 16. Call me quietly by name
  • 17. I see the target
  • 18. How many flights?
  • 19. Let’s clean up a little
  • 20. Who is faster?
  • 21. Saving up for a trip around the world
  • 22. Summary of “Functions”. Part 2
  • 23. Eighth program: “Money makes money”
  • 24. Ninth program: “The Eternal Question”
Let’s clean up a little
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

How many flights?

Now we have a function that counts how many flights we have to take to the same destination to accumulate the necessary number of miles.

To find out how Muffin can get to Tokyo quicker, we need to compare the number of flights to each destination. To do this, we need to call the calculateFlights function twice, for flights to Valencia and Lisbon, with the same value of the third argument (15000 miles to Tokyo).

Now, in order to understand what is more profitable for us, let’s find out how many business trips to Lisbon Muffin needs to go on before he can finally set out on vacation to Tokyo of his dreams. The distance to the capital of Portugal is 3617 km.

Comments

  • 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); console.log('Miles for the flight: ' + miles); var flights = Math.ceil(milesTarget / miles); console.log('Number of flights: ' + flights); }; calculateFlights(3118, true, 15000);

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

Console

The code has changed, click “Run” or turn autorun on.

Result

Goalscompleted
  1. Inside the calculateFlights function, delete log of values in the console.
  2. Return the number of flights using return from the calculateFlights function.
  3. Replace the calculateFlights(3118, true, 15000) function call with logging the following message in the console 'Required number of flights in business class to Valencia: ' + calculateFlights(3118, true, 15000).
  4. Add one more message below 'Required number of economy flights to Lisbon: ' + calculateFlights(3617, false, 15000).

Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

VISAMastercard

Log in

or

Forgot your password?

Sign up

Sign up

or
Log in

Restore access

Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

Forgot to connect your email to the profile? Email us and we’ll help.