I’m seeing lots of examples and questions about checking student answers in tables when the answers are or are equivalent to numeric fractions. However, I need to check student answers of the form 1/(4.5r) and 1/r when they type these into a table.
The code I’m using for other examples where the fractions are indeed numeric goes something like this:
cellErrorMessage(3,4): when this.cellNumericValue(3,4) = numericValue(“\frac{1}{18}”) “” otherwise “Divide 1 room by the time they would take to paint that room together. Leave your answer as a fraction.”
How do I change this up to use variables in the fraction, or do I need a completely different strategy?
Thanks.
Two ways:

Use this.cellContent(3,4) = “\frac{1}{r}” instead of cellNumericValue(3,4) = numericValue(“\frac{1}{18}”)

or define a function in “r” like :
Ans = simpleFunction(“\frac{1}{4r}”,“r”)
f= simpleFunction(“${this.cellContent(1,1)}”,“r”)
cellSuffix(1,1): when f.evaluateAt(3) = Ans.evaluateAt(3) “Correct” otherwise “”
1 Like
A few notes…
We’ve often not recommended method 1 (latex matching) because it was prone to errors. I feel like most of these, like the presence of extra spaces, have been fixed.
For the second method, just make sure you’re evaluating at multiple values. For example, (r2)/12
would validate as correct in the above sample.
There is a third method, pattern matching:
p = patterns
#define the pattern you want to match
pAnswer = p.fraction(p.integer.satisfies(`x=1`), p.product(p.integer.satisfies(`x=4`), p.literal(`r`) ))
check = pAnswer.matches(this.cellContent(1,1))
You could potentially combine more generic patterns (to accept) and evaluating a function. Patterns can be tricky to use, but can really help hone in on the forms you want to accept or reject.
1 Like