Juha-Matti Huusko
Juha-Matti Huusko

Reputation: 11

JSXGraph Moodle plugin move after student answer

I have a Moodle question with a JSXGraph image, say

<jsxgraph width="600" height="500">
    var brd = JXG.JSXGraph.initBoard(BOARDID, {boundingbox:[-5,5,5,-5], axis:true});
    var p = brd.create('point', [0,1]);
</jsxgraph>

How can I set

p.moveTo([0,2]);

if the student answers wrong?

I would need to access the board. Somehow I need to get the board ID.

Upvotes: 0

Views: 74

Answers (2)

Juha-Matti Huusko
Juha-Matti Huusko

Reputation: 56

Thank you. I have been using the STACK question type. I will try your approach.

Best wishes, Juha-Matti

(I do not have enough reputation to add a comment, so I have to write my message in this way.)

Upvotes: 0

Andreas
Andreas

Reputation: 81

What question type do you use? Ich would recommend to use Formulas. Then you can use our JSXGraph Moodle formulas extension. It is included in the JSXGraph Moodle filter (no files have to be installed additionally). You can find a documentation here: https://github.com/jsxgraph/moodleformulas_jsxgraph/blob/master/README.md.

In your case you can type:

<jsxgraph width="600" height="500" ext_formulas>

   // JavaScript code to create the construction.
   var jsxCode = function (question) {

      var brd = JXG.JSXGraph.initBoard(BOARDID, {boundingbox:[-5,5,5,-5], axis:true});
      var p = brd.create('point', [0,1]);
       
      if (question.isSolved)
         p.moveTo([0,2]);
    };

    // Execute the JavaScript code.
    new JSXQuestion(BOARDID, jsxCode, /* if you want to see inputs: */ true);

</jsxgraph>

This code would move the point to [0,2] when the question is displayed after submission.

I hope, I could help you.

Upvotes: 1

Related Questions