Javascript Questions on moodle quiz

Javascript Questions on moodle quiz

by Mithu Kuruvilla -
Number of replies: 17
Hi all
I want to use moodle quiz for a JavaScript course. Most of the question are programs with blanks provided somewhere in it. Students have to fill the blanks with correct JavaScript statements. So Embedded answers (cloze) question type is better.
But the problem is that I need a JavaScript interpreter to interpret the entire program or a parser to compare the answer given by the student with my answer key. Just string comparison wont work since its programming logic it may differ with individual.
Can I add a JavaScript interpreter interface to moodle quiz?
Can any one suggest what should I do?Its urgent.

Thanks in advance
Mithu Mary Kuruvilla
Average of ratings: -
In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

You might use REGEXP questions embedded in a Cloze question. Be aware however that the REGEXP question type is not (yet) part of regular moodle distribution and you'll need to hack the Clozetype (multianswer) a little to make it work.

Joseph

PS.- You can test it on my test site, Demo course, login as teacher1, password teacher1.

In reply to Joseph Rézeau

Re: Javascript Questions on moodle quiz

by Mithu Kuruvilla -
Thanks a lot for your reply...

I have gone through your Demo course. What I felt is the REGEXP question type is not what I want. It is best for short answer question but my requirement is not just that. In programming, logic may differ with people so we cant specify all the expressions through regular exp. This can be checked only if we interpret the entire program or parse the answer expression and compare it with answer key. Correct me if I am wrong and please do post your suggestion.

Mithu Mary Kuruvilla
In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
OK, I understand that what you want will not be possible with the REGEXP question type.
Joseph
In reply to Joseph Rézeau

Re: Javascript Questions on moodle quiz

by Mithu Kuruvilla -
Is it possible to get the question and answer in an XML file on submit instead of evaluating it. Then I can take this XML file to my application or for manual correction. Later an email can be send to inform the score and solution to each student.

Thanks
Mithu Mary Kuruvilla



In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
I presume that you want to take advantage of the automated marking. I have a similar need but with deductive derivations (and I don't have access to the core code). I use a simple interface which can be open from an essay question (with javascript) but that is only for manual marking that can be made more efficient with some more javascript that takes the answer and feed it to an interpreter. Currently I don't see any other way for automated marking of this sort of problems but to scorm a simple interface (editor + interpreter etc.) which allows for answering the question and also performs validation check. I haven't done the scorming part yet and from what I hear in the relevant forums, there are some open issues with the scorm module. But I'll have to give it a try.
In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Mithu Kuruvilla -
Thanks a lot for your reply...

This is exactly what I am thinking. Will use moodle for presenting the question and getting the answer.

In moodle on clicking the button "submit all and finish" it will get evaluated. Instead of getting evaluated I need to get the question and answer with the details of the student in any file format preferably XML format. Then I could give the XML file of each student to my application and evaluate it. Later I can send an email to each student from my application about the score and solution.

The other button "save without submit". Will it help me?

I know we can export and import the quiz in xml format. But how can we get the answer and question together in a file without evaluating it. I think it is similar to getting it for manual evaluation. Can I get your help?

Mithu Mary Kuruvilla

In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
Hi Mithu,

Here is a quick description of my approach and I'll add the details in subsequent posts.
  1. I use essay question.
  2. I add to the question description a button that imitates the behavior of the insert buttons of the HTML editor (e.g. the Insert Smiley button).
  3. My button opens a pop up with an html page in which the student enters the answer.
  4. When the student finishes she clicks Insert (in the pop up window) and the answer goes into the HTML editor.
  5. The student, then, can save or save without submit; the answer is stored in the quiz.
  6. Now, you can set up the html page in the pop up window such that when the answer is returned from the pop up window to the HTML editor it includes a string which is the answer formatted as XML (and you can put it in a hidden filed).
  7. You add to the question description another button which extracts the XML string and either feed it to an interpreter (if it can be executed from javascript) or display it in a pop up window from which you can copy it and save in a file.
  8. After you check the answer you can mark the essay question and also add the interpreter output.
  9. And so, answers marks and feedback are stored in the quiz.
I'll post the javascript I use soon. smile

Itamar

In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -

An example

The question:


derivation_question.jpg

The 'Open derivation editor' button code:

open_derivation_editor_code.jpg

  • InsertDerivation function - a variation on the HTML editor's Insert function which I took from the HTML editor core code.
  • obj - for passing the id of the editor's instance in the question to the function so that the answer will go to the right place.
  • file-name.html - the html file which is opened in the pop up.
  • strDerivation - the string returned from the pop up and entered into the HTML editor.

The completed answer:

completed_derivation_question.jpg



In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Kevin Oldham -
I tried this code with some edits to change from using the insertDerivation editor to using (I hope!) Moodle's Insert Special Character editor. However, the popup does not open when I click on the button. I wonder if anyone might have suggestions for code changes that might help. Itamar, I wonder what the part that you first underlined; "editor_5db013afcda3669b8c52fb0417e0b3dd" does in the code. Forgive me for lack of programming understanding. Thanks to anyone that can offer help.
In reply to Kevin Oldham

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
This function works exclusively with Moodle's HTML editor as it calls the editor functions (e.g editor._getSelection(), editor.insertHTML(...)). "editor_5db013afcda3669b8c52fb0417e0b3dd" is a unique editor id in a specific page (which is extracted from the page after the question is created) and is different for each question. In short, it can't be used it as is for your purpose, but it can show the way.

I'll try to come up with code which does what you need after breakfast smile

Itamar
In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
Hi Kevin,

Here is a quick and dirty solution you can try out and if it works for you we can work out the details: (that's a revised version of a previous post which I deleted)

* Create a CLOZE question.
* Add question description
* In HTML mode enter

<div>{:SHORTANSWER:=ÐhelloÐ#}<span Xonclick="myInsertChar(this.parentNode);"><img title="ins_char" alt="ins_char" src="full path of icon_ins_char.gif" border="0" hspace="0" vspace="0" /></span></div>

* Remove X
* Set the correct answer of the question
* Set the url of the ins_char image (you can copy it from the tool bar of the question editor by right click -> copy image location)
* Save
* Create DESCRIPTION question
* In HTML mode enter

<script Xlanguage="javascript">
<!--
function myInsertChar(obj) {
var textField=obj.getElementsByTagName("input")[0];
if (textField==null) {
alert("No text field was found");
} else {
Dialog("your moodle server's url/moodle/lib/editor/htmlarea/popups/dlg_ins_char.php", function(cChar) {
if(!cChar) {
return false;
}
if (document.selection) { //IE
textField.focus();
sel = document.selection.createRange();
sel.text = cChar;
} else if (textField.selectionStart || textField.selectionStart==0) { //FF
var startPos = textField.selectionStart;
var endPos = textField.selectionEnd;
textField.value = textField.value.substring(0, startPos)+cChar+textField.value.substring(endPos, textField.value.length);
}
return true;
}, null);
}
}
//-->
</script>

* Remove X
* Set the url of your moodle server.
* Save
* Add both questions to the quiz.
* Now, for this solution to work you need to have an ESSAY question in the quiz page (as I said, quick and dirty) so if you don't have one already as part of the quiz you need to create an essay question (can be empty) and add it to the quiz. It is needed so that the required js for the special character pop up window will be included in the page.
* When in the quiz click on the ins_char img to insert a special character.

Give it a try and let me know if it works or if anything in my instructions requires clarification.

Itamar smile

In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
Just thought you would like to see what the code above should produce.

ins_char_sa.jpg

Itamar

In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Kevin Oldham -
You are awesome! This worked great. I think you really have us on our way. I tried using these changes with a 1 question per page quiz and (as I thought) it didn't work. That's because the js from th essay needs to be on the same viewed page; right?

So, I think our next step will be to see how we might work this code into the embedded cloze question type and leave the short answer type alone. (Embedded cloze gives us more flexibility for correcting the question.) I wonder if we can just put this coding into the display.html file or if it needs to be in question_type.php. Also, I wonder what we might need to do to eliminate the need to have the essay question on the page. This might allow us to have 1 question per page. (We like to do 1 question per page do to taking the quiz on many laptops in a classroom setting.)
In reply to Kevin Oldham

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -
Hey Kevin,

(this is a revised version of a previous post I deleted)

I'm glad it's working. Here is a quick solution to the one question per page issue and for getting rid of the essay question.

Attached is a revised version of the Moodle dialog js in which all reference to HTMLarea are commented off. That leaves only the dialog functionality which is needed for opening the popup.

You need to upload that file to somewhere accessible.

I've already included the myInsertChar function code in that revised Dialog js file so you can get rid of the DESCRIPTION question and simply add the following line to every CLOZE question you create (in HTML mode)

<script type="text/javascript" src="XXXXXXXXXX/myDialog.js"></script>

Replace XXXXXXXXXX with the full path to myDialog and also in the myInsertChar function in the file replace XXXXXXXXXX with the path to the popup window.

Let me know if it works for you.

Itamar smile

In reply to Itamar Tzadok

Re: Javascript Questions on moodle quiz

by Arbuthnot Smith -
Hi, I haven't quite got it to work. Firstly, I think you still need to add the <span onclick... part, or at least without this is didn't do anything.

I now have the content of the question as

{1:SHORTANSWER:=éâè}
<script type="text/javascript" src="http://localhost/moodle/myDialog.js"></script><span Xonclick="myInsertChar(this.parentNode);"><img title="ins_char" alt="ins_char" src="http://localhost/moodle/lib/editor/htmlarea/images/icon_ins_char.gif" border="0" hspace="0" vspace="0" /></span>


without the X. It brings up the special characters box when I click on the symbol, but doesn't enter them into the text box.

Help would be very much appreciated.

Arb.
In reply to Arbuthnot Smith

Re: Javascript Questions on moodle quiz

by Arbuthnot Smith -
Hmm, it is now working exactly as above. Sorry for the false alarm! And many thanks for the solution above.

Arb.
In reply to Mithu Kuruvilla

Re: Javascript Questions on moodle quiz

by Itamar Tzadok -

An example (cont.)


The derivation editor dialog window:

derivation_editor.jpg

The dialog window code:

derivation_editor_dialog_code.jpg

  • The code is a slightly modified version of the Moodle pop up javascript functions, adjusted to my needs (e.g. the structure of the returned string (strDerivation)).
  • Note the inclusion of the library popup.js
  • I added the resizeDlg function because the HTML editor's function which opens the dialog window assigns predefined dimensions and a default when it does not recognize the target (as in my case) and it locks the resize function of the dialog window.
I hope that helps. smile Let me know if any other details are required.

Itamar