Checking for Correctness

I am trying to figure out what code to use. I am wanting students to look at the linear piecewise functions and then write the function and domain in the table. Then be able to get feedback if what they typed is correct as well as showing in the dashboard if they are correct.

The equations in the table are what the answers should be.

Any assistance would be greatly appreciated. It is the last slide of the activity.

Graphing Piecewise Functions • Activity Builder by Desmos

This is the code for the red graph, but just copy and make a few changes for the green. This goes in your table CL:

# idea from   https://teacher.desmos.com/activitybuilder/custom/5eb18d6a22180f0ace8005e3
fRed = simpleFunction("${this.cellContent(3,2)}","x")
correctRed = fRed.evaluateAt(2) > 2.99 and fRed.evaluateAt(2) <3.01 and fRed.evaluateAt(6) > 4.99 and fRed.evaluateAt(6) < 5.01
correctRedDomain = this.cellContent(4,2)="x>2"
cellContent(3,3): when correctRed  "✅" otherwise ""
cellContent(4,3): when correctRedDomain "✅" otherwise ""

The >= requires LaTeX for \le and \ge:

# idea from https://cl.desmos.com/t/checking-correctness-of-an-inequality/1542
correctGreenDomain= this.cellContent(2,2) = `x \le 2`
cellContent(2,3): when correctGreenDomain "✅" otherwise ""       

Thank you for your help. Can you please explain to me what the numbers represent for when looking at the correctRed? I am trying to duplicate but I am confused on how you determined the numbers. Also, how would you code for a less than or equal to symbol?

For correctRed:
fRed.evaluateAt(2) > 2.99 and fRed.evaluateAt(2) <3.01
means I’m taking the function they entered and checking the value at x = 2 for the red graph. Since decimal accuracy can be an issue for non-integers, I’ve seen many posts that recommend checking an interval, so I’ve checked 2.99 < y <3.01 for y = 3. This probably could be replaced in your activity with
fRed.evaluateAt(2) = 3

Since you’re graphing lines, you need to check 2 points, so you add the check at x = 6:
fRed.evaluateAt(6) > 4.99 and fRed.evaluateAt(6) < 5.01
which you might be able to replace with
fRed.evaluateAt(6) =5

For x <= 2, you need LaTeX: x \le 2
\ge works for >=. See the last post for how this should be coded. (The ` mark is on the same key as the ~ in upper left key on the keyboard.)

Note that you could pull values from the graph to make the code more generic instead of entering specific y-values.

Just FYI, simpleFunction defaults in terms of x, if no variable is specified.
So, this:

can be written as
fRed = simpleFunction("${this.cellContent(3,2)}")