Checking Equations in Variables Other Than X

Hi all,

I’m trying to edit screen 5 of Michele Anderson’s awesome step-checking activity, found here: Solve Linear Equations • Activity Builder by Desmos

Students input equations into the table and receive positive feedback as long as the equation they write has the same solution as the original equation.

Here is the original code, which works as long as the cell in the table has an equation in x, but does NOT work if the students use “n” as the variable instead.



Later in the code, it makes it so that when “check1” is true, they get feedback that it’s correct, and otherwise they get feedback that it’s incorrect.

I want to be able to have equations that use variables other than x (e.g. n, p, etc.). So, I’ve tried to implement the solution offered in this post:

So I did this:

left1=simpleFunction(parseEquation(this.cellContent(1,1)).lhs, "n")
right1=simpleFunction(parseEquation(this.cellContent(1,1)).rhs, "n")

But then got the same error described in this post:

And I’m not really understanding well enough how to apply the solution described there to this situation. Nothing I’ve tried changes the error.

Thanks for any help you can provide!

EDIT NOTE: Edited to link to Michele’s original activity instead of my edited copy.

This is a great question. I was curious to try to explore this issue, so I made a copy of your activity, and inside that I made a Screen 6 that is a copy of Screen 5, but now with the variable “n” instead of “x”.

It seems to work ok:

Here’s what I think was the cause of the problem. The final check line:

final1= (left1=“n” and check1) or (check1 and right1=“n”)

no longer works if left1 becomes a function, made by simpleFunction().
Desmos will allow you take an expression (made by parseEquation) and see whether it is equal to “n”, but you can’t compare a function to the letter “n”. However, you need to use simpleFunction in order to tell Desmos to use the variable “n” instead of “x”.

Here is a solution that works, although it’s not very beautiful:
Keep left1 and right1 as they are:

but then make function versions of them using simpleFunction(), with “n” as the variable:

then turn those functions into numbers, using evaluateAt()
left1_val = left1_func.evaluateAt(answer)
right1_val = right1_func.evaluateAt(answer)

and, finally, compare those two numbers:


Don’t forget to change the variable name from “x” to “n” in this part at the bottom of the script:
final1= (left1=“n” and check1) or (check1 and right1=“n”)

In the copy of the activity linked here, I didn’t make eight copies of this script, to cover eight possible cells in the table. I guess for robustness against the students making overly multi-step tables you might want to do that. I’m not sure if CL currently allows for a less clunky way of doing this, with some sort of loop instead of eight manually edited copies.

I hope this helps,


1 Like

Since the only change you want to make is the letter that you are using, I think an efficient way to do this would be to use substituteLatexVariable and just change whatever letter you want them to use into x. So if you have your equation written in terms of n, you could change the first part of the code for each table row to something like:

letter = "n"

eqn1 = substituteLatexVariable(this.cellContent(1,1),letter,"x")

Then everything else should work as normal because left1 and right1 will now be in terms of x as the rest of the code expects. By using the letter variable, you can then change the letter in the equation right there without having to change it in all the rest of the code.

1 Like

Oh, that’s nice! I didn’t know about that substituteLatexVariable() command. Looks useful!

Thanks so much both of you for your help! I wish I could give you both “solution” credit. :slight_smile:

1 Like