- script.js
JavaScript
var mode = 'reverse'; // Printing driver mode
var pageNumber = 5; // Copied page number
var copyCount = 7; // Number of copies
var totalPages = 6; // Pages in the document
var startPage = 1; // Starting page
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);
}
}
if (mode === 'reverse') {
for (var reversePage = totalPages; reversePage >= 1; reversePage--) {
muffin.print(reversePage);
}
}
Result
Goalscompleted
Let’s add a mode for printing even and odd pages of the document.
- Add a check for the
'alternate'
mode at the end of the program. - Inside this check, add a loop where the value of
alternatePage
variable increases by2
from the valuestartPage
tototalPages
inclusively. - Inside the loop, add the page printing command
alternatePage
.
Comments