HTML Academy
Previous task
Functions1/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”
Long-distance flight
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Fasten your seat belts

You were just getting into the office when you received a letter from Muffin that was labeled as “urgent”.

Meow! I want to go on vacation. They say that there is some delicious salmon in Irkutsk: I got so fed up with St. Petersburg fish.

Count how many bonus air miles I can get if I fly with MuffAir. My gut feeling as an avid discount hunter suggests that I can make a profit here.

The distance to Irkutsk is 4125 km. The number of air miles is 25% of this distance.

I’m waiting for the result!

For a start, let’s clarify what “air miles” are. These are bonuses from airlines that can be accumulated after each flight, and then these miles can be used to “pay” for a flight to a certain city. Bonus miles are accrued in different ways. In MuffAir, as we have already learned, bonuses constitute a percentage of the flight distance.

In our code, the distance is stored in variable distance, and the percentage is already converted to a fractional number and stored in variable percent.

These values ​​are enough to get the right number of miles: multiply the distance by percentage.

Comments

  • script.js
JavaScript
var percent = 0.25; var distance = 4125;

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. Calculate the number of miles using formula distance * percent and write the result to variable miles.
  2. Log the result in the console: console.log('We’ll get ' + miles + ' miles for the flight to Irkutsk');.

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.