Checking latex in a Math answer box in reference to another

Hello everyone, I’m new with Desmos but I have some coding experience. I was wondering someone could help me with this.

I’m creating a quadratic equation activity where roots are complex, 2+1 and 2-1 so I created two Math answer boxes input for students to input their answers. I was able to use this code to check the first answer:
check = this.latex = 2+i or this.latex = 2-i
correct: check

For the second Math answer box, I will like to check that:

  • List item if the first answer entered is 2+i then the correct will be 2-i
  • List item if the first answer entered is 2-i then the correct will be 2+i

How can I do this? Any other advise will be appreciate.

Use ‘when’ and ‘otherwise’. Here, name your first box something like box1, then in the second box the code would be

check = when box1.latex=`2+i` this.latex=`2-i`
when box1.latex=`2-i` this.latex=`2+i`
otherwise FALSE

Thank you so much. It worked perfectly. I tried something like that before but couldn’t for some reason. Thank you so much once again @Andrea_McPhee

1 Like

Glad I could help!

I just edited my answer because I realized you only need the last ‘otherwise’ in a compound statement.

1 Like

If you want to use an evaluative method instead of latex matching, you can “trick” desmos into evaluating complex answers by making a function in terms of i.

How can I do that? Please a beginner, with example (it could be an activity where you have used it). Thank you

For box1 CL:

#student input as a function in terms of i 
f=simpleFunction(this.latex,"i")
#checking for 2+i
checkPosI= f.evaluateAt(0)=2 and f.evaluateAt(3)=5
#checking for 2-i
checkNegI= f.evaluateAt(0)=2 and f.evaluateAt(3)=-1
correct: checkPosI or checkNegI

For box2 CL repeat above except last line

correct: (box1.script.checkPosI and checkNegI) or (box1.script.checkNegI and checkPosI)