I'm currently working on a program that would randomly generate linear inequalities with solutions and explanations. My questions and solutions are generating perfectly; however, whenever I "submit" my answer, I get an internal error -- "undefined has no properties". Honestly really not sure what part is undefined, so I was wondering if someone could take a look at my code and highlight my error. Thanks!
Problem2(1, "Solve linear inequality level 2", 2, rand => {
/*
* For this problem, randomly generate a linear inequality, e.g. 7(4x + 5) + 7 < 8x - 5
* The answer should be the interval of values for x.
*
* Inequalities with <, >, >=, and <= should all be generated.
*
* Complete the explanation of how to solve the equation.
*/
/* Create constants for the problem. Integers range from -10 to 10. 0 and 1 aren't included..*/
const n1 = rand.integerExcl(-10,10, [0, 1])
const n2 = rand.integerExcl(-10,10, [0, 1])
const n3 = rand.integerExcl(-10,10,[0, 1])
const n4 = rand.integerExcl(-10,10,[0, 1])
const n5 = rand.integerExcl(-10,10,[0, 1])
const n6 = rand.integerExcl(-10,10,[0, 1])
/* The ansNum is the number that x will either be greater than (or equal to) or less than (or
equal to), depending on the sign. This is cast to a fraction, and then used in each case below
depending on the sign.*/
const ansNum = Num.F((n6-n4-n1*n3),(n1*n2-n5))
/* Each sign should have an equal change of generating.
Generates an answer based on each sign. */
const p = rand.prob()
var n = "m"
var a = "()"
if (p < 0.25) {
n = "<"
if ((n1*n2-n5)>=0) {
a = `(-00, ${ansNum})`
}
else {
a = `(${ansNum}, 00)`
}
} else if (p < 0.5) {
n = ">"
if ((n1*n2-n5)<0) {
a = `(-00, ${ansNum})`
}
else {
a = `(${ansNum}, 00)`
}
} else if (p < 0.75){
n = "<="
if ((n1*n2-n5)>=0) {
a = `[-00, ${ansNum}]`
}
else {
a = `[${ansNum}, 00]`
}
}
else {
n = ">="
if ((n1*n2-n5)<0) {
a = `[-00, ${ansNum}]`
}
else {
a = `[${ansNum}, 00]`
}
}
const sign = `${n}`
return {
instructions: `Solve the linear inequality for |||x|||. Write your answer in interval notation.`,
question: `|||${n1}*(${n2}x + ${n3}) + ${n4} ${sign} ${n5}x + ${n6}|||`,
explanation: `Begin the problem by distributing <||${n1}||> to <||(${n2}x + ${n3})||>. Combine like terms
to get <||(${n1*n2-n5}x) ${sign} (${n6-n4-n1*n3})||>. Make sure to flip the sign when
multiplying or dividing by a negative number! `,
answers: [a.toString()],
answerType: {form: "input"},
}
})
Aucun commentaire:
Enregistrer un commentaire