-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMultiplicationProblem.js
More file actions
46 lines (43 loc) · 1.16 KB
/
MultiplicationProblem.js
File metadata and controls
46 lines (43 loc) · 1.16 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
class MultiplicationProblem {
constructor(first, second) {
this.first = first;
this.second = second;
}
get display() {
return this.displayProblem() + " = " + this.answer() + " choices " + this.choices().toString();
}
get allChoices() {
return this.choices();
}
displayProblem() {
return this.first + " x " + this.second;
}
answer() {
return this.first * this.second;
}
choices() {
const answ = this.answer();
var choices = new Set();
choices.add(answ);
choices.add(answ + 10);
choices.add(answ + 1);
choices.add(answ + RandomUtils.getRandomInt(1,10));
//Ensure we have 6 choices
var choicesRange = (answ > 100) ? answ : 100;
while(choices.size < 6) {
choices.add(RandomUtils.getRandomInt(1,choicesRange));
}
return Array.from(choices);
}
static generateProblems(range) {
var problems = new Array();
if(range && range.start >= 0 && range.end >= range.start) {
for(var i = range.start; i<range.end+1; i++) {
for(var j = range.start; j<range.end+1; j++) {
problems.push(new MultiplicationProblem(i,j));
}
}
}
return problems;
}
}