# Table Check with Button

Goal: I want students to enter values into a table then hit a submit button. Upon hitting the button, I want the table to provide checks and x’s to show correct and incorrect input as well as change the button text. I only want this to happen when the button is hit each time.

Problem: This works EXCEPT if you change a number in the table, the check or x with change before you hit the button again (which could allow kids to randomly guess until they just check a check mark).

Here’s what I have so far:

Screen 7 on this activity: 7.1.7 Scale Drawings (Y) â¢ Activity Builder by Desmos

TABLE:
a = table1.cellNumericValue(2,2)
b = table1.cellNumericValue(2,3)
c = table1.cellNumericValue(2,4)
d = table1.cellNumericValue(2,5)

capture(“a”): a
capture(“b”): b
capture(“c”): c
capture(“d”): d

t= button1.timeSincePress()
button = button1.pressCount()

cellSuffix(2,2):
when t<20 and button >0 and a = 28 “
when t<20 and button >0 and a > 28 “
when t<20 and button >0 and a < 28 “
otherwise “”

cellSuffix(2,3):
when t<20 and button >0 and b = 15 “
when t<20 and button >0 and b > 15 “
when t<20 and button >0 and b < 15 “
otherwise “”

cellSuffix(2,4):
when t<20 and button >0 and c = 24.8 “
when t<20 and button >0 and c > 24.8 “
when t<20 and button >0 and c < 24.8 “
otherwise “”

cellSuffix(2,5):
when t<20 and button >0 and d = 1 “
when t<20 and button >0 and d > 1 “
when t<20 and button >0 and d < 1 “
otherwise “”

BUTTON:
a = table1.cellNumericValue(2,2)
b = table1.cellNumericValue(2,3)
c = table1.cellNumericValue(2,4)
d = table1.cellNumericValue(2,5)

capture(“a”): a
capture(“b”): b
capture(“c”): c
capture(“d”): d

disabled: button1.pressCount = 4

label: when button1.pressCount = 1 “Check Answers: Try #2
when button1.pressCount = 2 “Check Answers: Try #3
when button1.pressCount = 3 “Check Answers: Try #4
when button1.pressCount = 4 “No more tries”

capture only works in a button. You’ll want to change your a in your cellSuffix to

button1.lastValue("a")

similar for the other three variables.

Also, instead of separate lines for a>28 and a<28 you can use a nested when-otherwise:

cellSuffix(2,2):
when t<20 and button >0
(when button1.lastValue("a") = 28 "✅"
otherwise "❌")
otherwise ""

Thank you so much it worked like a charm!!! Now my students will get to exercise some mathematical independence.

1 Like

I would like to EASILY just add a button that executes the code that checks the table.
I was wondering if there is a way to treat the button the way a macro button would be created using excel VBA. I have not used a button component yet, and I figure this might be a good start. I was hoping there was a way to just add a “when: button > 0” at the top of the code…

Not sure exactly what you mean but something like this would accomplish what you want(i think).

With respect to this particular activity though i’d be very cautious implementing this. It’s very very fragile since you’re checking correctness based purely on an exact latex string match - maybe not the best way to go about it.

There’s no “easy” way to change/run multiple sinks in the CL. Correct me if I’m wrong but I’m inferring you want the feedback in the table to be blank until the button is pressed.

Not an easy fix, but to achieve this I’d change to a three tiered conditional:

presscount = CheckAnswersButton.pressCount
check1= t.cellContent(1,2)=3x\left(x-3\right)
cellContent(1,3): when presscount=0 ""
when check1 "✔️"
otherwise "❌"
correct: check1 and check2 and check3...


A few tips (and note the changes above)

1. It’s not necessary to create the presscount variable in the button. You can still access pressCount from a button as seen in the first line of code.
2. Using backticks (on the ~ key upper left) instead of quotes will improve latex matching, which can be fragile anyway as @Mike_Gleeson noted.
3. I used a variable to perform the correctness check. This way you can also use it for the correct sink as added in the last line above.
(Sometimes, instead of checking the pressCount of a button I’ll this for the first line of the three-tiered conditional use:
when isBlank(this.cellContent(1,2)) or this.cellHasFocus(1,2) ""

1 Like

The problem with the “table checking” that I am having is that if the answer is 7x and the student wants to type 7x^2, they will get the green check before they hit the ^ button, so they will accidentally get the correct answer.
so I was looking for a workaround. Also, I know the ‘x’ in the box before they enter an answer is not ideal, but it makes the coding so much easier. But now that you showed me that, I will make that improvement…thanks!!!

Is check1 a boolean, or does it contain the latex you assigned? Because if it is not a boolean, then I am so confused as to how the “correct: check1 and check2…” works. I assumed those things had to be “true” for the correct to be true.
And if it is a boolean, is there a way to store latex into a variable?

Thanks for your help…the backtick thing is a nice little improvement. …I know the simplefunction route is usually better, but this is a lot easier to program for a beginner…

Yes, check1 is a Boolean, so the output is true or false, thus the correct: sink as I coded it requires each check to be true. (If you put correct: true in your component, you would always have a checkmark.)

You can store pretty much anything as a variable except numberLists or sinks.

The bottom line of my last post will fix the premature check or X because of the cellHasFocus(1,2) (I initially put the wrong cell coordinates because I usually use cellSuffix). The feedback will always be blank while typing into the cell, and will only appear if you move away from it.