Check for correctness for coordinates

I want to check for correctness for coordinates that my students type in (x,y) format (not on a graph) and to give my students feedback that says correct or incorrect. I have been trying to make it work for the past 2 hours, I need help!

Laura,

Have you tried using parseOrderedPair? It will create an ordered pair object that has saved my bacon multiple times. If you are coming from a Math Input field, it sets up like this:

studentAnswer = parseOrderedPair(mathInput.latex)

You can then access the x and y-coordinates from the ordered pair object for checking against the correct answers: studentAnswer.x will give you a string version of the x-coordinate, and studentAnswer.y would be the y-coordinate.

Also, if this was remarkably unhelpful and you don’t mind sharing your activity, I’m sure the community would love to give it a look and help out if you give us a link!

Happy scripting!
-Shaun

2 Likes

Thank you for the suggestion! I am new to this and I think I have a long way to go. I appreciate you taking your time to help me!

Do you have extra bacon? :bacon:

The parse ordered pair kept giving me an error code, I messed around with it for a bit and gave up. I ended up adding a button that says “Check my answer” then in the CL I put this:

suffix: when this.latex="\left(-1,-1\right)" and button23.pressCount>0 “:heavy_check_mark:” otherwise “”
correct:this.latex="\left(-1,-1\right)"

I think it is working so far, I at least didn’t get an error code.

I always start the day with extra, but it disappears between second breakfast and elevenses.

2 Likes

Everything from parseOrderedPair outputs a string, so if you’re trying to see if it equals -1 you need to use it within numericValue:

ans=parseOrderedPair(this.latex)
check=numericValue(ans.x)=-1 and numericValue(ans.y)=-1
suffix: when check and button23.pressCount>0  "✅" otherwise ""
correct: check
1 Like