# Check Answer Includes Equivalent Expressions

**URL:** <https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982>\
**Category:** Questions\
**Tags:** validation, correctness\
**Created:** [November 19, 2020, 6:52pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982 "2020-11-19T18:52:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)\
**Post date:** [November 19, 2020, 6:52pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/1 "2020-11-19T18:52:14Z")

</div>

I was able to borrow enough code and activity slides to make an activity that checks student answers when they enter it in the submit box. However, I can only get it to accept one answer, when I want it to accept multiple formats of the same answer. For example Slide #3 has the correct answer as “-5p-20”, but I want it to also accept “-5p+ -20” as correct. Is there a way to adapt the code to have more equivalent expression answers?

> **[Distributive Property Practice • Activity by Sian Sleight](https://classroom.amplify.com/activity/5fadc475da71b038b7f8565d)**
>
> Practice the distribute property with integers and check your work.

More specifically, the code is here.  
correct = this.latex = “-5p-20”  
correct: correct  
Is there a way to make it like this?  
correct = this.latex = “-5p-20” OR “-5p+ -20”  
correct: correct

---

<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:** [November 19, 2020, 9:09pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/2 "2020-11-19T21:09:43Z")

</div>

It’s recommended you use calculations to check expressions instead of matching latex.

That said, use backticks instead of quotes and you’ll have less problems with extra spaces and such. For `or` statements, you need to use entire conditions for each part of the or statement:

```auto
correct = this.latex = `-5p-20` or this.latex = `-5p+-20`

```

---

<div class="post-metadata">

**Author:** ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)\
**Post date:** [November 19, 2020, 10:09pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/3 "2020-11-19T22:09:47Z")

</div>

I am piecing all this together without really understanding it, so I don’t know what this means, “use calculations to check expressions instead of matching latex.”  
But that other bit totally works, thank you, thank you!!

---

<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:** [November 19, 2020, 10:53pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/4 "2020-11-19T22:53:45Z")

</div>

An example would be:

```auto
answer = simpleFunction(this.latex, `p`)
check = answer.evaluateAt(0)=-20 and answer.evaluateAt(1)=-25
        and countNumberUsage(this.latex,5)=1 
        and countNumberUsage(this.latex,20)=1
correct: check

```

answer takes student input and turns it into a function.  
check evaluates the function at 0 and 1 to see if they get correct solutions. countNumberUsage checks that 5 and 20 are each used once (it can’t recognize negative numbers) in order to mark incorrect other expressions like `p-6p-20` that would still evaluate the same.

It’s a little tricky to learn, but it is more accurate in correcting than trying to match latex which can have problems sometimes. Though it does seem to work most of the time.

---

<div class="post-metadata">

**Author:** ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)\
**Post date:** [November 19, 2020, 11:09pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/5 "2020-11-19T23:09:35Z")

</div>

Oh my word that is clever. I would need to see an example of the code to figure out how to adapt it. Are there any example activities that have used this approach?

---

<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:** [November 20, 2020, 12:23am UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/6 "2020-11-20T00:23:43Z")

</div>

The code above would work for your specific example. There are probably more here in the forums.

This thread has some discussion using a table:

> [@Checking Correctness of Table Entries](https://cl.desmos.com/t/checking-correctness-of-table-entries/758):
>
> I am hoping someone can help me fix my code in order to have a student’s table value entries show up as correct (with a checkmark) on the teacher dashboard. I have managed to do this for all of my multiple choice questions, however I would also like to do it for the numerical values the students enter into a table. Here is my attempted code: figure1number = table1.cellNumericValue(1,1) figure2number = table1.cellNumericValue(1,2) figure3number = table1.cellNumericValue(1,3) correct = when (…

---

<div class="post-metadata">

**Author:** ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)\
**Post date:** [November 22, 2020, 6:26pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/7 "2020-11-22T18:26:35Z")

</div>

All right, I found the CL webinar videos in that thread, so I can start to understand the computation layer code. Thank you for your time and help!

---

<div class="post-metadata">

**Author:** ![mrkleing](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mrkleing/32/1108_2.png) [@mrkleing](https://cl.desmos.com/u/mrkleing)\
**Post date:** [November 25, 2020, 3:26pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/8 "2020-11-25T15:26:30Z")

</div>

If interested, I made it so you can type any thing equivalent

for example

-50p + 20 can be typed in as 3dogs -4cats +25p-75p+19+1-3dogs+4cats would also be marked as correct.

---

<div class="post-metadata">

**Author:** ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)\
**Post date:** [November 25, 2020, 4:59pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/9 "2020-11-25T16:59:43Z")

</div>

Yes! That would be great for my combining like terms activity…

---

<div class="post-metadata">

**Author:** ![mrkleing](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mrkleing/32/1108_2.png) [@mrkleing](https://cl.desmos.com/u/mrkleing)\
**Post date:** [November 25, 2020, 7:07pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/10 "2020-11-25T19:07:52Z")

</div>

check out slide 1

> **[Homework Template • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5fbea8e44ce64e402ff11445)**
>
> by Gregg Klein

---

<div class="post-metadata">

**Author:** ![Bryan\_Henning](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/bryan_henning/32/345_2.png) [@Bryan\_Henning](https://cl.desmos.com/u/Bryan_Henning)\
**Post date:** [March 20, 2021, 4:40pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/11 "2021-03-20T16:40:57Z")

</div>

Hi Daniel, thank you for your post!

The function I’m trying to check is a trig function (specifically the answer should be the sine function in this case).

I tried modifying the code like this, but the CL gives an error message saying "Unknown function ‘sin’ ".

answer = simpleFunction(this.latex)  
check = answer.evaluateAt(0)=sin(0) and answer.evaluateAt(1)=sin(1)  
correct: check

Is there something else I need to know about using trig functions within CL?

---

<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:** [March 20, 2021, 6:59pm UTC](https://cl.desmos.com/t/check-answer-includes-equivalent-expressions/1982/12 "2021-03-20T18:59:32Z")

</div>

Any type of calculation performed in CL requires the use of simpleFunction( ).evaluateAt( ) or numericValue( ). For your specific check:

```auto
answer = simpleFunction(this.latex)
check = answer.evaluateAt(0)=numericValue(`\sin(0)`) 
      and answer.evaluateAt(1)=numericValue(`\sin(1)`) 
correct: check

```

Note that CL performs trigonometric functions in radians. If this doesn’t work try `{ }` instead of ( ) for the sin functions.
