HTML Academy
How much does printing cost?
Loops17/28
Back to the list of tasks
  • 1. New project: driver development
  • 2. Managing the number of copies
  • 3. Learning the for loop
  • 4. Correcting the loop
  • 5. Printing the pages in reverse order
  • 6. Printing only odd pages
  • 7. Printing only even pages
  • 8. Printing driver: copy mode
  • 9. Printing driver: all pages
  • 10. Printing driver: pages in reverse order
  • 11. Print driver: even and odd pages
  • 12. Print driver: switching evens and odds
  • 13. Accumulation in the loop
  • 14. Checks in loops
  • 15. Searching for an even number
  • 16. How much does printing cost?
  • 17. Economy printing
  • 18. Saving ink
  • 19. Summary of “Loops”. Part 1
  • 20. Third program: “Protein shake!”
  • 21. It’s been a “while”
  • 22. The while loop, summation
  • 23. Another project: a dart machine
  • 24. Dart machine: accumulating misses
  • 25. Dart machine: defeat
  • 26. Dart machine: final scoreboard
  • 27. Summary of “Loops”. Part 2
  • 28. Fourth program: “Mad Dryer”
Saving ink
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Economy printing

Our printer is often used by students, and saving money is very important for them. Saving on everything. Our analysts found out that teachers usually read no more than the first three pages of all reports, course books and other student documents. From this secret knowledge, the idea of ​​a printing mode for students was born: the first three pages are printed as usual, and then we save as much as we can on all the remaining pages (that is, we use two times less toner)!

Now we don’t just need to increase the value of consumptionTotal for each iteration by 70, but we also need to check which print mode we are using (economy or standard) and which page of the document (number) we are printing. Conditions will be useful here.

Use the condition in the loop to check the print mode. If we are in economy mode, we will catch pages with a number greater than 3 and print them with lower ink consumption. We will write half of the consumption as consumptionPerPage * 0.5.

Comments

  • script.js
JavaScript
var totalPages = 6; // Total number of pages var consumptionTotal = 0; // Total toner consumption var consumptionPerPage = 70; // Toner consumption per page for (var page = 1; page <= totalPages; page++) { muffin.print(page); // Add the check here consumptionTotal += consumptionPerPage; console.log(consumptionTotal); }

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. After the consumptionPerPage variable, create variable economyMode, which contains false.
  2. In the loop after calling muffin.print(), add a condition that works if economyMode equals true and if the number of the current page page is greater than 3.
  3. Inside this condition, increase consumptionTotal by consumptionPerPage * 0.5 with the help of the += operator.

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.