-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiples.js
More file actions
93 lines (75 loc) · 2.25 KB
/
Copy pathmultiples.js
File metadata and controls
93 lines (75 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function findingMultiplesWorksheet(){
template.createTitle(doc,"Finding Multiples Worksheet");
template.addNameDate(doc);
//Template end
doc.fontSize(12);
doc.text("Find five multiples of the following: ");
for(let i=0;i<10;i++){
appendQuestion();
}
//add a logo
template.addLogo(doc);
//add a border
template.addBorder(doc);
createAnswerKey();
template.addLogo(doc);
//add a border
template.addBorder(doc);
function appendQuestion(){
let arr=createQuestion();
(window.store).push(arr);
doc.fillColor("black");
doc.text(arr[0],{
});
doc.fillColor("white")
doc.text(arr[1],{
})
doc.moveDown();
}
function createQuestion(){
let arr=[];
//generate random integer
let number = Math.floor(Math.random()*100)+1;
let equation = number + ' : ';
window.numb++;
return ["\n"+window.numb+") "+ equation ,createAnswer(equation)+"\n"];
}
function createAnswer(equation){
let multiples = [];
let number = (equation.substring(0,equation.length-3)).trim();
let number = parseInt(number);
for(i=1;i<6;i++){
multiples.push(i*number);
}
let str = multiples.join(", ");
return "Answer: " + str;
}
function createAnswerKey(){
doc.fillColor("black");
doc.addPage();
doc.fontSize(20).text("Answer Key",{
align:"center",
underline:true,
});
doc.fontSize(12);
for(items of window.store){
doc.fillColor("black");
doc.text(items[0]);
doc.moveDown();
doc.fillColor("red");
doc.text(items[1]);
};
};
// finalize the PDF and end the stream
doc.end();
stream.on('finish', function(){
url = stream.toBlobURL('application/pdf')
let iframe = document.getElementById("i")
iframe.src = url;
y = (iframe.contentWindow || iframe.contentDocument);
if (!y.document.body.style.backgroundColor) {
y.document.body.innerHTML = "<h1 style='text-align:center'>You are using a mobile browser.</h1> <h3 style='text-align:center'>Your download should have initiated</h3>";
y.close();
}
});
}