# Checking random fraction generated problems

I wanted to know is it possible to check the solutions of random generated fraction problems. I would also like the answers to send to a table on the last slide to allow the teacher to check for correct answers on the last slide. Below is what I have so far:

Here’s some code you can put in the input component.

disableEvaluation: true

note = Note1

answer = simpleFunction(a/b+c/d, a, b, c, d).evaluateAt(note.script.a, note.script.b, note.script.c, note.script.d)

p = patterns
fraction = p.anyOf(p.fraction(p.number, p.number), p.mixedNumber)
isFraction = fraction.matches(this.latex)

correct: check


The disableEvaluation is used so the student doesn’t see the decimal equivalent show up. Maybe you don’t mind it there, so it’s not necessary to include it.

In addition to calculating the answer based on the randomly generated numbers, I included a pattern check to see if the answer is in fraction form or mixed number form.

If you want a check to show in the teacher dashboard, put readOnly: true in the sketch component.

There are many ways to send the answer to the table on the last screen. Here’s one way:

cellContent(1,2):
otherwise "${Input1.latex}"  Thank you so much. Do you know if it possible for the random generated problem to be inputted into the first column of the table also? Also if I change the operation or the type of number (decimal) will that affect the code? To send the problem to the table, this will work: cellContent(1,1): \frac${Note1.script.a}{${Note1.script.b}}+\frac${Note1.script.c}{${Note1.script.d}}  You will need to rename the note components on each screen because they all have the same name. Note2, Note3, etc will be fine. If you change the operation, you just need to adjust the code for the simpleFunction to match the problem. If you only want a decimal answer and not a fraction, you can use this to pattern match. p = patterns isNumber = p.number.matches(this.latex)  Thank you so much. You have saved me a ton of time. Ok. I changed from fractions to decimals for my RNG problems. I can’t get the coding right for it to show if the answer is correct and it also will not show the problem in the table on the last slide. Where are my errors? I think two things might be causing problems. The first thing I noticed is that you were using a variable named e. I think when you use that in simpleFunction, it doesn’t actually treat that as a variable but rather the constant value. I also think the notation you used in the simpleFunction wasn’t able to be interpreted by the computer. Try this instead (I renamed the last two variables f and g in the note): answer = simpleFunction(a+b/10+c/100+d+f/10+g/100, a, b, c, d,f,g).evaluateAt(note.script.a, note.script.b, note.script.c, note.script.d, note.script.f, note.script.g)  As for the table, I saw some extra backslashes and braces that were causing the problem. This should work: cellContent(1,1): ${Note1.script.a}.${Note1.script.b}${Note1.script.c}+${Note1.script.d}.${Note1.script.f}\${Note1.script.g}