## WeBWorK Main Forum

### Passing arguments from GeoGebra/JavaScript to WeBWorK?

by tim Payer -
Number of replies: 4

Thanks to some help from the Forum, I was able to recreate the WeBWork problem that uses an embedded GeoGebra applet example for the bounded area under a curve displayed at http://webwork.maa.org/wiki/GeoGebraWeb1#.WwxgjqrRWUl

I feel confident enough that I could create more of these, but only so far as the example goes.

That is, the example above passes 2 arguments ($c and$d) from the WeBWorK problem to its embedded GeoGebra applet. The resulting area under the curve gets calculated separately in WeBWork and GeoGebra. Then a wide tolerance is given in the answer blanks, I am assuming for any discrepancy that occurs between GeoGebra’s CAS and WeBWorK’s binary calculation?

At any rate, what if the GeoGebra applet had a number of manipulatives that (with JavaScript) result in a single value being passed on to WeBWorK as a score for the student’s accuracy in positioning these manipulatives? How difficult is this to create as a prospective homework problem?

Specifically I would like to embed Marc Renault’s GeoGebra applet in a WeBWorK homework problem:

http://webspace.ship.edu/msrenault/GeoGebraCalculus/derivative_try_to_graph.html

Thirteen coordinate points must be moved on their respective vertical axis to approximate the sketch of the derivative for a randomly generated function on the interval [-6, 6]. The student is prompted to move these 13 points and a resulting accuracy score is given on the students attempt. The student can continue to improve their accuracy, but not their initial score unless they opt to reset the graph and begin again with a new function.

Marc Renault has granted permission to use his applet, and passed on the html code to me, but I imagine this poses a bigger challenge? It is just a single value that would need to be passed onto WeBWork though, so doesn’t this sound like a workable problem?

I have read over the JavaScript/WebWork example but it is not a robust example.

Any help you can give to help shed light on embedding this applet is most appreciated.

Sincerely, Tim

In reply to tim Payer

### Re: Passing arguments from GeoGebra/JavaScript to WeBWorK?

by Sean Fitzpatrick -
If I recall correctly, WeBWorK can pass parameter values to GeoGebra, but GeoGebra can't pass numerical values back to WeBWorK.

It can display numerical information in the applet for a student to enter into WeBWorK, but it can't enter that information for the student.
(For example, we have a probability question that uses GeoGebra to produce an interactive probability applet, where students can adjust sliders to obtain area under part of a normal curve, and the applet displays the result on screen, but we also need to have R running to compute the result and pass it to WeBWorK.)

Update: maybe this is a case of "we couldn't get it to work, but..."
Some of the examples on the Rochester page linked to in the post by Joel Trussell that appeared just after yours suggest that this might actually be possible. See, for example,

(Edited by Michael Gage - original submission Wednesday, 30 May 2018, 11:45 AM)

In reply to Sean Fitzpatrick

### Re: Passing arguments from GeoGebra/JavaScript to WeBWorK?

by Michael Gage -
You pass information back from geogebra to webwork by inserting the information into "answerBoxes" - html input elements. You can make these visible or make them hidden if you don't want students to see the information being passed back.

The following example, taken from

<input type="button" value="set coords of B: " Xonclick="setCoords('B', setXfield.value, setYfield.value);">
<input type="text" name="setXfield" id="setXfield" size="5" value="6">
<input type="text" name="setYfield" id="setYfield" size="5" value="3"> 

places the coordinates of point B in the input blanks setXfield and setYfield.

The function setCoords is defined by Geogebra.

The webwork code concerning all applets is in the files

and

These files provide interfaces for Java applets, Flashapplets, Geogebra applets (both Java applet version and HTML5 version) and HTML5 web applets.

The API and files are ripe for review since Java and Flashapplets won't work in most browsers these days. Furthermore the HTML5 versions of Geogebra (and flashapplets) are much easier to install in web pages and webwork which should allow us to simplify the API considerably.

The project of replacing the existing flash and java applets with HTML5 versions would also be valuable.

setting debugMode =1 in the applet installation code will make all of the hidden input fields visible which will make it easier to understand the applet communication process.

In reply to Michael Gage

### Re: Passing arguments from GeoGebra/JavaScript to WeBWorK?

by Michael Gage -
From You Zhou: "
Hi, Mike

Thanks for the information.

One specific feature that we are not sure is: is there a way of embedding multiple answerboxes to a single applets. Currently the way of getXML sends us the answer as a single list. Currently we are using the customized list checker. But if we can use multiple answerboxes corresponding different variables from a single applet. We should be able to do answer checks more flexibly.

Regards,
Joe
"

I've added a different version of the "position the circle" geogebra applet that illustrates explicitly
how to put information into several boxes instead of packing them into a list:

The original is at

the new version with separate (non-hidden) answer blanks is the next problem at

setting the debugMode to 1 or 2 will give you much more information about what is going on.

Replacing NAMED_ANS_RULE with NAMED_HIDDEN_ANS_RULE hides the view of the answer
blank from the student.

To disable the automatic creation of the NAMED_ANS_RULE "answerBox" set
the option "includeAnswerBox => 1" to "includeAnswerBox => 0"

Hope this helps.

In reply to Michael Gage

### Re: Passing arguments from GeoGebra/JavaScript to WeBWorK?

by Joe Zhou -
Thank you, Mike. We are happy with what we have now.