# How to check student answers in table that involve fractions with variables?

**URL:** <https://cl.desmos.com/t/how-to-check-student-answers-in-table-that-involve-fractions-with-variables/7360>\
**Category:** Questions\
**Tags:** patterns\
**Created:** [October 4, 2024, 4:49pm UTC](https://cl.desmos.com/t/how-to-check-student-answers-in-table-that-involve-fractions-with-variables/7360 "2024-10-04T16:49:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![barbra.steinhurst](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@barbra.steinhurst](https://cl.desmos.com/u/barbra.steinhurst)\
**Post date:** [October 4, 2024, 4:49pm UTC](https://cl.desmos.com/t/how-to-check-student-answers-in-table-that-involve-fractions-with-variables/7360/1 "2024-10-04T16:49:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EdTech\_Singh](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edtech_singh/32/4707_2.png) [@EdTech\_Singh](https://cl.desmos.com/u/EdTech_Singh)\
**Post date:** [October 4, 2024, 7:48pm UTC](https://cl.desmos.com/t/how-to-check-student-answers-in-table-that-involve-fractions-with-variables/7360/2 "2024-10-04T19:48:04Z")

</div>

Two ways:

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

2. 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 “”

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [October 5, 2024, 3:14pm UTC](https://cl.desmos.com/t/how-to-check-student-answers-in-table-that-involve-fractions-with-variables/7360/3 "2024-10-05T15:14:53Z")

</div>

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, `(r-2)/12` would validate as correct in the above sample.

There is a third method, pattern matching:

```auto
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.
