You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
923 B
38 lines
923 B
import BaseModel from './base.model';
|
|
|
|
const AdditionModel = Object.create(BaseModel);
|
|
|
|
AdditionModel.generate = function(n, level) {
|
|
const equals = [];
|
|
const notequals = [];
|
|
const target = level + 5;
|
|
const midpoint = Math.ceil(target / 2);
|
|
|
|
let g1, g2, b1, b2;
|
|
|
|
for (let i = 1; i < midpoint; i++) {
|
|
g1 = i;
|
|
g2 = target - i;
|
|
|
|
b1 = Math.max(1, i - Math.ceil(Math.random() * 3));
|
|
b2 = Math.max(1, target - i - Math.ceil(Math.random() * 3));
|
|
|
|
equals.push(`${g2}+${g1}`);
|
|
equals.push(`${g1}+${g2}`);
|
|
|
|
notequals.push(`${b2}+${b1}`);
|
|
notequals.push(`${b1}+${b2}`);
|
|
}
|
|
|
|
return this.buildResults(equals, notequals, n);
|
|
};
|
|
|
|
AdditionModel.getTitle = (level) => {
|
|
return `Equals ${level + 5}`;
|
|
};
|
|
|
|
AdditionModel.getError = (value, level) => {
|
|
return `Oops! ${value} does not equal ${level + 5}.`;
|
|
};
|
|
|
|
export default AdditionModel;
|
|
|