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