Check Answer Includes Equivalent Expressions

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?

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

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:

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

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!!

An example would be:

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.

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?

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:

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!

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.

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

check out slide 1

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?

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

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.