It is possible to include JavaScript in WebAssign questions, using the HTML standard tag, <Script Language= "JavaScript">. JavaScript also can be written to interact with a Java Applet. One important difference from writing JavaScript for other applications is that a WebAssign tag, <EQN $numAnim>, should be included in the name of every function and object created by the JavaScript. When WebAssign processes a question to be sent to the user, this will be replaced by a number. This mechanism ensures that different problems or different instances of the same problem do not address the same functions or objects. The very first time this tag is used in a problem, it should be incremented to get a new number for the particular question by using <EQN ++$numAnim>. Here is an example of a question that uses JavaScript to provide a hint:
<Script Language = "JavaScript">
var hintnumber_<EQN ++$numAnim> = 0;
function GiveHint_<EQN $numAnim>(){
if(++hintnumber_<EQN $numAnim> == 1){
alert("Hint: Think outside the box.");
}
else{if(hintnumber_<EQN $numAnim> == 2){
alert("Hint: Does a side have to be a straight line?")
}
else{
alert("Enough hints already!")
}
}
}
</SCRIPT>
The Sphinx asks, "How many sides does a circle have?"<BR> <_> <BR>
<A HREF = "JavaScript:GiveHint_<EQN $numAnim>()">Hint</A>
This example pops-up an alert window that says “Hint: Think outside the box” the first time Hint is clicked, “Hint: Does a side have to be a straight line?” the second, and “Enough hints already” after this.


Some WebAssign instructors are using Java applets in WebAssign questions. Here are the steps for putting an applet into a WebAssign question:
Here is an example of code copied from Wolfgang Christian's Physlet® site*
http://webphysics.davidson.edu/physletprob/ch14_animator/default.html
The code to be deleted from steps 3 and 4 is highlighted.

document.animator.setDefault();
Your code should now resemble the following code, with the changes from steps 5 and 6 highlighted.

<EQN $animator = "animator_".$QUESTION_ID.'_'.($numphyslet++);''>
This defines the name of the applet for WebAssign and allows WebAssign to recognize it. It also ensures that if you have more than one copy of this applet on a page, they won't interfere with each other. If you have more than one applet in a question, for instance, an animator and a datagraph, this first line will need to define a couple of names:
<EQN $animator = "animator_".$QUESTION_ID.'_'.($numphyslet++);
$dataGraph = "dataGraph_".$QUESTION_ID.'_'.($numphyslet++);''>
<a href = JavaScript:initApplet_<EQN $animator>()>Click here to start.</a>
<!--http://webphysics.davidson.edu/physletprob/ch14_animator/default.html-->
Your code should resemble the following code with the changes in steps 7-10 highlighted.

Be careful not to add line breaks and spaces to the applet code as you make the necessary changes. One extra space or line break can prevent the applet from working properly.
WebAssign has copies of the Physlets on our server. For the Physlets, you can use $PHYSLETPATH. That is
CODEBASE = '<EQN $PHYSLETPATH>'
The following table lists the applets available from our servers. If you would like us to include an applet, please contact us at support@webassign.net.
|
APPLET |
CODEBASE and other information |
|
Animator, Bar, BField, Blackbody, Circuit, DataGraph, DataTable, Doppler, Efield, EMWave, EnergyEignevalue, Faraday, Filters, Hydrogenic, Molecular, Optics, Pipes, Poisson, QTime, Reflection, Ripple, Slider, SPlotter, STools, Superposition |
$PHYSLETPATH |
|
JME |
$APPLETPATH Molecular Editor from Novartis AG |
* Christian, Wolfgang and Belloni, Mario, Physlets: Teaching Physics with Interactive Curricular Material, (Prentice Hall, 2001).