How can I code a table to check if a student input is evaluated in the given expression?

Here is my activity. Evaluate using a table

I know how to code it to have exact correct answers in a table but I do not know how to have it evaluate at any input a student may choose for their x value.

Try this in your table component.

f = simpleFunction(`2x+3`, `x`)

cellContent(1,3):
  when isBlank(this.cellContent(1,1)) or isBlank(this.cellContent(1,2)) ""
  when f.evaluateAt(this.cellNumericValue(1,1))=this.cellNumericValue(1,2) "âś…"
  otherwise "❌"
1 Like

You can also use the graph for the sketch that is on the screen already.

2 Likes

You guys are awesome! They both work great. Thank you so much :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts:

I might also add the suggestion to expand the second line so that it won’t display the correctness until after they click outside of the cells for the coordinates. That will discourage them from fishing for a checkmark.

f = simpleFunction(`2x+3`, `x`)

cellContent(1,3):
  when isBlank(this.cellContent(1,1)) or isBlank(this.cellContent(1,2)) or this.cellHasFocus(1,1) or this.cellHasFocus(1,2) ""
  when f.evaluateAt(this.cellNumericValue(1,1))=this.cellNumericValue(1,2) "âś…"
  otherwise "❌"
2 Likes

Do you always have to use a simple function when student input is not a numerical value? Is there a way to just check the input being something like x^{2}+5 ??

EDIT: studentInput = this.latex to whatever cell names (e.g. cell12 = cellContent(1,2))

Sorry that your question was lost. Welcome!

Generally, evaluative methods, as at least part of a check, are recommended as they’re more robust and less prone to error, but there are a number of ways to check something like x^{2}+5.

Least recommended is latex matching, although this has been improved some with formatLatex, which trims off coefficients of 1 and removes extra spaces that formerly made things very tedious to match!

studentInput = this.latex
check = formatLatex(studentInput) = `x^{2}+5`

Then, there’s pattern matching which can be tricky to learn but can be useful if you want to accept different forms like 5+x^{2} (you can make it strict order, but the below accepts commutative representations.

p = patterns
answerPattern = 
     p.sum(p.integer.satisfies(`x=5`), p.exponent(p.literal(`x`), p.integer.satisfies(`x=2`) ) )
check = answerPattern.matches(studentInput)

We can also do combinations of strategies:

f = simpleFunction(studentInput)
answerPattern = p.sum(p.integer, p.exponent(p.literal(`x`), p.integer)
checkPattern = answerPattern.matches(studentInput)
checkEval = f.evaluateAt(0) = 5 and f.evaluateAt(-2) = 14
check = checkPattern and checkEval