- script.js
JavaScript
var mode = 'document'; // Printing driver mode
var pageNumber = 5; // Copied page number
var copyCount = 7; // Number of copies
var totalPages = 6; // Pages in the document
if (mode === 'pageCopy') {
for (var copies = 1; copies <= copyCount; copies++) {
muffin.print(pageNumber);
}
}
if (mode === 'document') {
for (var page = 1; page <= totalPages; page++) {
muffin.print(page);
}
}
Result
Goalscompleted
Let’s add the printing mode of the document pages in the reverse order.
- At the end of the program, add a check that compares
mode
with the value of'reverse'
. - Inside this check, add a loop that decreases the value of
reversePage
fromtotalPages
to1
inclusively. Decrease the value ofreversePage
by one at each iteration. - Inside the loop, add the print command for the current page
reversePage
. - Change the value of the
mode
variable to'reverse'
.
Comments