Solving for y, literal equations

Hi!

I have created an activity where students have to solve the equation for y. I copied previous code that someone was kind enough to provide me with, but I can’t seem to get it to work when students enter the “y=” part of the equation. Here’s a link to my activity:
https://teacher.desmos.com/activitybuilder/custom/65157793ff30737ab771a5d8

Any help is appreciated!

Hi there Phillip! There are a few ways to approach this. Here’s one idea:

You could start by parsing the student’s input as an equation and checking to see if either side of the equation matches the string “y”. In the case that one side of the equation matches “y”, just grab the other side. If neither side of the equation matches “y”, use the student’s input as it was entered.

studentString = table7.cellContent(1,1)
eq = parseEquation(studentString)
exp = 
  when p.literal(`y`).matches(eq.rhs) eq.lhs
  when p.literal(`y`).matches(eq.lhs) eq.rhs
  otherwise studentString

In this example, you could then use exp in place of ans1 and it should be good to go. Hope that helps!

Thank you! Much appreciated.