Checking Math Input for an Equation

I want to give students a picture of a hanger diagram and have them type the equation that represents it. I have it set up as a “math input” component. The answer to the particular one that I’m working on is 3x+2=x+5. I want them to type that and receive feedback that says “Good job!” if they get it right. If they get it wrong, I want it to say “Try again! Remember that the green square represents x and the blue triangle represents 1.”

Could anyone help me in writing code for that?

(Edit: There were some quotes that I think may have messed up the code, which I fixed.)

For your particular problem, the left and right sides should probably checked separately for each number, then whether they each evaluate to the correct solution.

checkNumbers = countNumberUsage(left,3)=1 and countNumberUsage(left,2)=1
          and countNumberUsage(right,5)=1
checkSolution = simpleFunction(left).evaluateAt(1.5) = simpleFunction(right).evaluateAt(1.5)
correct = checkNumbers and checkSolution

parseEquation takes an equation and splits it into left and right expressions. You can access them using “lhs” and “rhs”. You can also use differenceFunction which will create a function of lhs-rhs.

You could combine checkNumbers and checkSolution into correct instead of separately, just thought it would be easier to understand this way.

You can use “this” instead of “inputName” if you’re in the input component.

Thanks so much for your response! I think that’s a little over my head. I tried copying and pasting the code but it didn’t work, and because it’s a little over my head, I didn’t know how to change it to work for my slide. I ended up using this:

a = exp1.latex

when isUndefined(a) “Enter a value to balance the hanger.”
when exp1.latex=“3x+2=x+5” “You did it! Make sure you click ‘Submit’ below.”
otherwise “Keep thinking! What’s the equation?”

Thanks again! I’m enjoying learning the coding language for this :).

I edited the code above. I think I had some quotes that were probably messing things up.

Trying to match latex exactly can cause problems. I put “inputName” instead of whatever your input is called, which it looks like was “exp1”. So you could cut/paste, then just replace inputName with exp1.

Then, for your content:

content: when isUndefined(exp1.latex) "Enter a value to balance the hanger."
         when correct "You did it! Make sure you click 'Submit' below."
         otherwise "Keep thinking! What's the equation?"

I’ll try it. Thanks! :slight_smile: