# Answer that is a fraction

I can use CL to check non-repeating decimals, but not fractions. After reading through other posts I tried 5\frac{1}{3}. I tried adding \ and \ in front as well as a tick mark, but nothing works. I also want it to show correct if students type 16/3. What am I missing in the code?

1 Like

I would check the rounded value to whatever number of decimal places you feel is appropriate then use countNumberUsage if you’re looking for a specific format.

correct = numericValue("\\round(${this.numericValue},5)") =numericValue("\\round(16/3,5)") and countNumberUsage(this.latex,16)=1 and countNumberUsage(this.latex,3)=1  Thanks, I appreciate the help! Because I wanted students to also be able to enter 5-1/3, I got rid of the countNumberUsage. I added notcountNumberUsage to prevent students from copying and pasting the problem into the answer, John Rowe showed me that. Misunderstood which form you wanted. You can use countNumberUsage for 5, 1, and 3 if you wanted the mixed fraction. The other way to use countNumberUsage is to check the total number of numbers used. ...and countNumberUsage(this.latex)=3...  would check if there were three numbers in the students answer, so 16/3 would be wrong. But with just that something like 1 + 13/3 would also be correct, without checking specific numbers. 1 Like I also was trying to find a way checking fractions that were repeating decimals. I started using this method above and it worked but it was a lot for me to wrap my brain around. I found another method that will check all fractions (whether they are simplified, mixed number, improper, etc.). It uses the concept of the constant of proportionality in proportional relationship equations. In order for it to check 16/3 or 5 1/3 is correct, here is the code I use. –coefficient of y is the denominator your want to check, coefficient of x is the numerator. z = “3y=16x” myLine=xyLine(z) m=myLine.slope correct: Componentname.numericValue = m More recently I’ve learned that simpleFunction does a better job when making comparisons than numericValue. Great. Could you give an example of the code that you use for that? Thanks, check= simpleFunction("${this.latex}").evaluateAt(0)=simpleFunction("\frac{2}{3}").evaluateAt(0)


It doesn’t really matter what you evaluateAt, since there’s no variable in the function.

1 Like

Thanks @Daniel_Grubbs I just used this to get my activity sorted.

Would you mind explaining each part of this code, please. Thanks for your help

If you’re replying to the above solution:
1 The numericValues are comparing student input to 16/3, each rounded to 5 decimal places (the double \ is not supported anymore and should be only one ).
2. countNumberUsage takes latex for the first parameter and a number for the second parameter, which will output how many times that number occurs in the latex. It counts the number not the digits. So the second part is checking if a student used 16 and 3 once each in their answer.

You could use pattern matching instead now, which wasn’t available when I posted this solution.