HTML Academy
Previous task
Loops1/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”
Managing the number of copies
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

New project: driver development

You proved that you can create programs with complex logic. And the Muffin entrusts you with a big and serious project: development of drivers for the new printer of MuffinRoks ® brand. A driver is a special program that allows a computer to control technology (mouse, keyboard, printers, scanners, monitors and other devices).

The new printer is simple enough, it should be able to print all the pages in direct and reverse order, print even and odd pages and make copies of one page. And your driver program should make this happen.

However, the test printer has not yet been sent to us (the development is taking a long time, after all, the Muffin’s engineers sleep 20 hours a day). Therefore, the logic of the drivers will be worked out with the help of a special command muffin.print, which takes into account an input page number. Here is an example:

// Logs in the console the “Print page #1” line
muffin.print(1);

Now this command just logs the text in the console. But as soon as the test sample is sent, it can easily be reconfigured to work with a printer.

Let’s start with a simple task: you need to get the printer to print the specified page several times.

Comments

  • script.js
JavaScript
var page = 7; muffin.print(page);

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

The driver prints one page #7. Make it print it three times.

  1. Copy the line with the command muffin.print(page) in the end of the program.
  2. And once again.
  3. Replace the value of the page variable to 9.

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.