Here's another interpretation of the OP's objective, based on some parts of the code that don't make sense (to me, as yet) unless frac
is supposed to generate a new random fraction each time it is called.
nenner = {2, 3, 4, 5};
zaehler = {1, 2, 3, 4, 5, 6, 7, 8};
(* new random frac each evaluation (via SetDelayed)
I'd normally define it frac[] := ..., or even better
randFrac[] := ... *)
frac := RandomChoice[zaehler]/RandomChoice[nenner];
FormFunction[{"first" ->
<|"Interpreter" -> "Number",
"Label" ->
HoldForm@Evaluate[f1 = frac] + HoldForm@Evaluate[f2 = frac]|>},
If[#first == f1 + f2, "Right!", "Wrong. Try again?"] &,
AppearanceRules -> {
"Title" -> "Bruchrechnen",
"Description" ->
"Löse die Bruch-Aufgaben und gib das Ergebnis an",
"SubmitLabel" -> "Go!"}]
If you want to make sure that your random fractions do not reduce, so that the problem isn't simply 1 + 1
, filter out the denominators that are not coprime to the numerator:
frac := With[{z = RandomChoice[zaehler]},
z/RandomChoice[Select[nenner, CoprimeQ[z, #] &]]]
Other issues:
You can localize f1
and f2
by wrapping the whole in Module[{f1, f2}, <..code..> ]
. I didn't test this in the cloud, but it works on the desktop version.
The Interpreter
format "Number"
doesn't seem to accept fractions as numbers. It seems to me an oversight of WRI not to include fractions, given their interest in Computer-Based Math. "SemanticNumber"
will accept 58/15
for instance, as well as 58 fifteenths
. I'm not sure if it will accept German expressions. It did not accept 58 Fünfzehntel
nor 58 Fuenfzehntel
, which is the equivalent that Google Translate gave me. (I don't know if it's the right or wrong way to express 58/15.)