Capture History from Table Entry

Me again, using the random generator to eliminate the need for unnecessary worksheets or expensive subscriptions (thank you Desmos–you have changed my life).
I found this great code by Wes Overton that uses a table entry so the students can keep changing their answers until it is correct.
I want to know if it is possible to capture the count of correct emojis? Or… hm… capture history in the graph so at least something is populating so I can see how many problems students have answered?
Thank you!

cellContent(1,2): when n_1=1 and j_3=j_1 “:heavy_check_mark:” when n_1=2 and j_3=j_1 “:heavy_check_mark:” when n_1=3 and j_3=j_1 “:heavy_check_mark:” when n_1=4 and j_3=j_2 “:heavy_check_mark:” otherwise “:thought_balloon:

Sure, just set the capture based on correctness, total that up.

So, I am looking at previous code from Daniel and Aethir. This should work, right?

Correct =
when n_1=1 and j_3=j_1 1
when n_1=2 and j_3=j_1 1
when n_1=3 and j_3=j_1 1
when n_1=4 and j_3=j_2 1
otherwise 0
capture(“correct”): Correct

It looks like you have multiple possibilities that something could be correct, so this code should work. Then you can send the history of “correct” to a calculator to find the totals and number of attempts (if you want).

You can clean it up a little (assuming only integers for n_1):

when j_3=j_1 and n_1>0  and n_1<4 1
when j_3=j_2 and n_1=4 1
otherwise 0

Right, I see that. Thanks guys!

Ugh. It’s not working. Do I need to reference cellContent(1,1) where the expression is being entered, or is t1.history okay?
numberList(C_{ounter}): t1.history(“correct”)

Distributive Property Practice • Activity Builder by Desmos

I noticed a couple things that may have been causing problems. It looked like the method used for checking the expression wasn’t working, so I used some pattern matching to check for correctness (it accepts both forms of the expression using the Commutative Property). I also noticed that capturing was being done in the table, but that code needs to go in the action button component. This should be working like you wish.

Score, thank you so much for your help!!
The code for the previous version was pretty straightforward math, so I was having an easy time of adapting it for negatives or combining like terms. I’m having a harder time adapting your code, so I have a few more questions.

If I change the random numbers to include negatives, ${,1)}, the code only accepts the additive inverse and not subtraction. It has to be a sum? Is there a way to allow it for the difference as well? I can’t see how to fix that.

If I change the problems to subtraction here, it won’t show as correct any more. Maybe for the same reason?
content: when n_1=1 “${a_1}(${b_1}x - ${c_1})
otherwise “${a_2}(${c_2} - ${b_2}x)

And easy combining like terms would go something like?
when n_1=1 “${b_1}x + ${b_2}x + ${c_2}
when n_1=2 “${b_1}x + ${c_2} + ${b_2}x
when n_1=3 “${c_2} + ${b_1}x + ${b_2}x
otherwise “${c_1} + ${b_2}x + ${c_2}

sum1 = when graph.script.n_1=1 or when graph.script.n_1=2 or when graph.script.n_1=3 numericValue(${graph.script.b_1}+${graph.script.b_2})
otherwise numericValue(${graph.script.c_1}+${graph.script.c_2})
sum2 = when graph.script.n_1=1 or when graph.script.n_1=2 or when graph.script.n_1=3 numericValue(${graph.script.c_2})
otherwise numericValue(${graph.script.b_2})

p = patterns

expression = p.sum(p.sum(p.number.satisfies(“x={sum1}"), p.literal("x")), p.number.satisfies("x={sum2}”))

Oh lord. I spend a lot of time trying to understand and play with it, but I really should be asking for help sooner. I’ll keep playing with it, but thank you, thank you for your continued help.

The pattern matching is fairly new and I’m still learning, so if you had other methods that worked, feel free to use them. I was just thinking about from previous experience that finding equivalent expressions can be tricky. Pattern matching helps with that. Jay has a bunch of tutorial videos if you’d like to learn more.

The sum pattern only works for addition, so if you want to include an additive inverse, you also need to include a difference pattern. Here’s an example where you could accept x-y and x+(-y).

p = patterns
sumPattern = p.sum(p.literal("x"), p.literal("-y"))
differencePattern = p.difference(p.literal("x"), p.literal("y"))
expression = p.anyOf(sumPattern, differencePattern)

correct: expression.matches(this.latex)

I updated the previous activity to include a second screen with subtraction problems.

Briefly - I saw Jay use a method that allows for flexibility, I believe here:

He created multiple patterns, like your sum and difference options. He then used


to figure out which one (if any) the student had used.

You can see that in the CL of the note in this example of his:


HaHa, the previous code didn’t blend well with the keeping tally of correct answers, so I am going to delve into this pattern matching code.
Thank you for your help and sharing this!