# Checking random fraction generated problems

**URL:** <https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577>\
**Category:** Questions\
**Tags:** patterns, validation, correctness\
**Created:** [August 4, 2021, 5:33pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577 "2021-08-04T17:33:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Lindsey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric_lindsey/32/1626_2.png) [@Eric\_Lindsey](https://cl.desmos.com/u/Eric_Lindsey)\
**Post date:** [August 4, 2021, 5:33pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/1 "2021-08-04T17:33:42Z")

</div>

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:

> **[Adding Fractions Weekly Review September Week 1 • Activity by Eric Lindsey](https://classroom.amplify.com/activity/610a8ed7491cd909563c7d46)**
>
> by Eric Lindsey

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [August 4, 2021, 7:47pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/2 "2021-08-04T19:47:42Z")

</div>

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

```auto
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)

check = this.numericValue=answer and isFraction

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:

```auto
cellContent(1,2):
when isBlank(Input1.latex) "⚠️ Go back and submit your answer"
otherwise "${Input1.latex}"

```

---

<div class="post-metadata">

**Author:** ![Eric\_Lindsey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric_lindsey/32/1626_2.png) [@Eric\_Lindsey](https://cl.desmos.com/u/Eric_Lindsey)\
**Post date:** [August 5, 2021, 12:35pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/3 "2021-08-05T12:35:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Eric\_Lindsey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric_lindsey/32/1626_2.png) [@Eric\_Lindsey](https://cl.desmos.com/u/Eric_Lindsey)\
**Post date:** [August 5, 2021, 12:40pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/4 "2021-08-05T12:40:27Z")

</div>

Also if I change the operation or the type of number (decimal) will that affect the code?

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [August 5, 2021, 2:06pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/5 "2021-08-05T14:06:23Z")

</div>

To send the problem to the table, this will work:

```auto
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.

```auto
p = patterns
isNumber = p.number.matches(this.latex)

```

---

<div class="post-metadata">

**Author:** ![Eric\_Lindsey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric_lindsey/32/1626_2.png) [@Eric\_Lindsey](https://cl.desmos.com/u/Eric_Lindsey)\
**Post date:** [August 5, 2021, 2:27pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/6 "2021-08-05T14:27:46Z")

</div>

Thank you so much. You have saved me a ton of time.

---

<div class="post-metadata">

**Author:** ![Eric\_Lindsey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric_lindsey/32/1626_2.png) [@Eric\_Lindsey](https://cl.desmos.com/u/Eric_Lindsey)\
**Post date:** [August 5, 2021, 6:14pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/7 "2021-08-05T18:14:54Z")

</div>

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?

> **[Adding Decimals Weekly Review November • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/610bf1bf027d4909c1e0e93f)**
>
> by Eric

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [August 5, 2021, 7:58pm UTC](https://cl.desmos.com/t/checking-random-fraction-generated-problems/3577/8 "2021-08-05T19:58:27Z")

</div>

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](https://en.wikipedia.org/wiki/E_(mathematical_constant)). 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):

```auto
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:

```auto
cellContent(1,1): `${Note1.script.a}.${Note1.script.b}${Note1.script.c}+${Note1.script.d}.${Note1.script.f}${Note1.script.g}`

```
