Interactive online courses HTML Academy
2026-03-09 12:24 Diff

Look at how quickly you are getting along! Let’s remember what else a printer should be able to do:

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.

All we have to do is print even and odd pages. Printing only odd pages is easy:

  • You need to start printing from the first page.
  • After each iteration of the loop, you need to increase the number of the current page by 2, and not by 1.

Perhaps you already noticed that in loops, an increase or decrease of variables by some number is regularly used. And we constantly have to write cumbersome structures, such as page = page + 1. Fortunately, JavaScript has several convenient operators that allow us to shorten the code. Here they are:

NameExampleAnalogIncrement (increase by one)i++i = i + 1Decrement (decrease by one)i--i = i - 1C-c-combo!i += 2i = i + 2

You can combine not only addition, but also other mathematical operations: subtraction -=, multiplication *=, division /= and calculating the remainder %=. For example, i *= 10 will do the same as i = i * 10.