WeBWorK Problems

javascript and html5 style problems

javascript and html5 style problems

by D. Brian Walton -
Number of replies: 1
My experience with javascript and html has just reached the point where I dare try to code a WeBWorK problem that uses interactive elements coded directly in javascript. It seems to me that this should be easier than the instructions for java or flash applets, since the javascript is a live part of the page itself.

Does anyone have experience in coding such a problem directly?

I think that I will need the following steps:

1) In the PG code, there should be a way to define the problem and pass the information to the javascript app. This will allow the WW server to generate the randomness for the problems and to ensure that a student sees the same version every time they load the problem.

2) The javascript then needs a way to submit an answer back to WW. I'd prefer to make this as direct as possible.

One problem that I anticipate is that the string sent to WW for checking answers is going to appear in Preview/Formatted form and would not make much sense. How do authors of other applet-based problems get around this?

Thanks,
- Brian
In reply to D. Brian Walton

Re: javascript and html5 style problems

by Michael Gage -
This sounds right to me.  Take a look at the Canvas object which is defined in the Applet API.  I wrote this a while ago at the beginning of the introduction of HTML5 and haven't had a chance to expand on it or clean it up.  

It was meant to present an API that looked pretty similar to the Java and Flash 
applet API, but as you observe the problem is actually simpler with HTML5. It will provide you with the tricks you need to preserve state in the javaScript applet and how to pass the result back to WeBWorK through ans_rule(s).  

I'm not sure what kind of data you are passing back to WeBWorK.  In the applets I wrote I passed the answer back in the same format that a student would use
to enter the answer.  If the answer is being passed back as TeX things could get
a bit trickier.

-- Mike

An example of HTML5 written by David Gage is at: