Checking negative fractions

Hello, I am trying to check students’ answers as they input values for slope of a line. How do I test for different ways of inputting negative fractions? I have only gotten it to work for when the negative is in the numerator, but I don’t expect that will be the natural way students enter it in. Thanks in advance!

Here is my code:

correct = input.script.correct

n = input.latex

when input.submitted and correct “Great Job! :+1:t4:
when input.submitted and n=\frac{-8}{2} “Close! Simplify the fraction”
when input.submitted “Not quite. Please try again. :-1:

You could replace your second to last line with:

when input.submitted and (n=`-\frac{8}{2}`or n=`\frac{-8}{2}`or n=`\frac{8}{-2}`) "Close! Simplify the fraction"

You could also use countNumberUsage, and you would have to account for all 8, -8, 2, and -2:

countNumberUsage(input.latex,2)=1 and countNumberUsage(input.latex,8)=1 and 
correct  "Close! Simplify the fraction"

countNumberUsage doesn’t accept negative numbers as a parameter, so you don’t need this part, but you do need to combine with an evaluative comparison to distinguish between positive and negative.

Thank you Susan. If the student types -8/2 in the (math) input field, it naturally puts the negative on the front (outside) of the fraction. How would I code to check for this?
Your suggested “when” statement duplicates the negative in the numerator. Is that where you meant to show this?
when input.submitted and (n=\frac{-8}{2}or n=`\frac{-8}{2}…

Put the negative before the /frac?

I had a typo–too much copy and paste, not enough double-check. I fixed it. You do need the backticks around LaTeX.