HTML Academy
Long-distance flight
Functions3/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”
Helper function
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Going the second circle

Meow! Thanks for the calculation!

When I come back, I want to fly to Kamchatka, eat some rainbow trout and check out the volcanoes.

How many miles will I get? I’ll have to fly for 9 hours, so this kind of sacrifice should be rewarded!

Your gut feeling was not lying! Muffin is planning yet another trip, but you got everything ready: you got the formula, and the condition for long-distance flights is taken into account.

Let’s add the mile calculation for the flight to Kamchatka.

To do this, we will have to repeat all the calculation steps for the first trip. The algorithm is the same, only the distance is different, and maybe the percentage. Let’s check!

As you can see, the result of our calculation isn’t a round number. There is no mistake, this is how JavaScript works. We will discuss why this happens in further courses. And we will round the numbers a little later.

Comments

  • script.js
JavaScript
// Copy the whole code below var percent = 0.25; var distance = 4125; if (distance > 10500) { percent = 0.35; } var miles = distance * percent; console.log('We’ll get ' + miles + ' miles for the flight to Irkutsk'); // Paste the code after this comment

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. Copy the entire code written before and paste it into the editor after the existing code.
  2. Change the second message in the console to 'We’ll get ' + miles + ' miles for the flight to Kamchatka'.
  3. Set value 11000 to the second variable distance.

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.