# Checking Text Answer in CL

I want to provide students with a message (like “Great Job!”) if they enter the correct solution to a system of equations in the text input and a message like (“check your work to see if you can find your mistake. If you need help, ask your teacher or a classmate”). Is there a way to do this?

You might want to use a math input instead of text input because extra spaces could unnecessarily mark the student’s answer wrong. Here’s an example of what you’re looking for.

2 Likes

I want to do something similar, but in my case I want to evaluate an equation that the student enters. See the activity here.

I am comparing an equation to an expected solution. Can I make this more tolerant of different forms?

solution = “y=-2x+5”

content:
when exp1b.timeSinceSubmit>0
when exp1b.latex=solution “Excellent!”
otherwise “Almost! Try again.”
otherwise “Write the equation of the line that is perpendicular to the line y=1/2x+3 through the point (4, -3).”

There is a nice solution for your question as well. In the first example, there is a function called parseOrderedPair that I used. It reads the input as an ordered pair and then you can match x and y values.

For your question, there’s a function called xyLine. It reads the equation and you can match the slope and y-intercept (along with a few other things). Check out slide 2 in the note and input component.

Thanks so much! That works much better.

Two other quick questions.

1. You changed the script associated with myNote1a to the following.
content:
when exp1a.timeSinceSubmit>0
when exp1a.script.correct "Excellent!"
otherwise "Almost! Try again."
otherwise "Write the equation of the line that is parallel to the line y=1/2x+3 through the point (4, -3)."


I’m confused by the expression “exp1a.script.correct”. Is that the sink for the exp1a or the variable (of the same name). If it’s the sink, couldn’t I just use “exp1a.correct”?

1. I was hoping to format my equation in the note better. Is there any way to enter (and have Desmos render) a latex expression within the content of a note? I’d like to do better than simply “Write the equation of the line that is parallel to the line y=1/2x+3 through the point (4, -3).”

Sorry, but one more question. I’m trying to apply your changes to other slides and am having difficulty checking for a slope of 1/3. I’ve tried:

equation = xyLine(exp2b.latex)

correct = equation.slope = 1/3 and equation.yIntercept=2

correct: correct


but I can see that it’s not that simple. Is there any way to compare the slope to a fractional value?

1. Since you had two different locations where you were defining the correct answer - the input component and the note component - I created a variable in the input component called “correct.” Since it was defined in the note component, I started by typing “exp1a” because that’s what you named the component. After that, .script looks for any defined variables in that component, and then .correct was the name of the variable. I suppose I should have named it something different so as not to be confused with the sink. Good question!

2. To format the equation better, try typing the equation into the graphing calculator, then copying and pasting into the code. Your example would look like this after pasting: y=\frac{1}{2}x+3 You will need to put backticks  around the equation and then insert another slash, so this should be the final look:

1 Like

For a non-terminating value, you need to set a tolerance range. Try equation.slope>0.333 and equation.slope<0.334

1 Like

The example you posted of the parallel lines is awesome, but one question. If instead of the student submitting an equation, if i wanted them to submit a function, like “f(x)=3x+5” how do I change the code for it to recognize f(x) instead of y?

If student input is exp1b, you could try using parseEquation, differenceFunction, and evaluateAt. It’s probably a good idea to create a single variable/boolean to check in your note. For example:

#This creates an expression of the left-hand side minus the right-hand side with variables x and y.

checkThis=parseEquation(exp1b).differenceFunction(“x”,“y”)

#This creates a true/false boolean by checking 2 correct solutions to the function

check=checkThis.evaluateAt(1,2)=0 and checkThis.evaluateAt(2,3)=0

content: when exp1b.timeSinceSubmit>0 and check “Excellent!”
otherwise “Almost! Try again.”

Your original content when otherwise won’t work for a few reasons.
I think you wanted 2 conditions to show ‘Excellent’. Each “when” should have a condition and result. ‘otherwise’ is the result if none of the ‘when’ conditions are true. So, you can’t have 2 ‘otherwise’

how can I do this but for 3 equations 3 variables. I tried expanding parseorderedpair to add a z component and it broke. Ideas?

myPair2 = parseOrderedPair(input2.latex)

content: when input2.submitted and numericValue(myPair2.x)=1 and numericValue(myPair2.y)=-2 and numericValue(myPair2.z)=4"Great job!"
when input2.submitted and (not(numericValue(myPair2.x)=1) or not(numericValue(myPair2.y)=-2 or not(numericValue(myPair2.z)=4)) “Check your work to see if you can find your mistake. If you need help, ask your teacher or a classmate.”
otherwise "Solve the system of equations.

       2x+3y+z=0


3x+y=1

x−2y+z=9

In this activity, slide 5, I have a system they have to solve and write as a coordinate. you could adapt that for three variables.

I think parseOrderedPair only works in (x,y) format. You could use countNumberUsage, but I don’t think there’s a way to determine correct order. I would suggest using a table to check for solutions. Column 1 would have x=, y=, and z= and Column 2 would be for student input.

do you know how to do table checks?

correct = this.cellNumericValue(1,2)=1 and this.cellNumericValue(2,2)=-2 and this.cellNumericValue(3,2)=4


Then in content, you can have content: when input2.submitted and table.script.correct...

1 Like

I have a couple tables in here that check for input and correctness

1 Like
#creates a function in terms of p
f=simpleFunction(this.latex,"p")

#checks if the function evaluates correctly at a few values for p
#use as many as you feel is appropriate
#(e.g. a quadratic would still be correct for these values)
correct= f.evaluateAt(1)=5 and f.evaluateAt(2)=6


Hi, I am trying to get a “Good job” or “Try again” type message to show up in an activity based off the students’ math input. This is what I have so far based off what I’ve seen in this thread, but I am still getting an error message.

The red squiggle line is identifying the issue. Your closing parenthesis is misplaced:

... not(myLine.slope=3)...
`

Thank you so much for your help!