sample for php and javascript question

sample for php and javascript question

von jupa poma -
Anzahl Antworten: 15

Hi,

I need some examples about questions in php and javascript, I try with this response for php

Answer

function algo($entero){

  return ($entero +1);

}

Test case 1

echo(algo(1));

Expected output

2

and the respose is  "Detailed test results unavailable. Perhaps an empty answer, or question not using Adaptive Mode?"


please help me


Als Antwort auf jupa poma

Re: sample for php and javascript question

von Nils Promer -
Hi jupa poma,

I'm not familiar with php and javascript, so I'm not able to check your code but regarding the adaptive mode I have an idea cause we had a similar problem.

It is maybe caused by the settings of the question behaviour.

Open the preview of your question. In "Attempt options" you can change the question behaviour on adaptive mode as shown on the picture.




After you saved this config "Start again with these options" your exercise should run the way want it to.

Hope this works.

Nils
Als Antwort auf Nils Promer

Re: sample for php and javascript question

von jupa poma -

thanks finally I put the questions, with the adaptive mode

<?php  function algo($entero){

  echo ($entero * $entero);

}?>

Test case 1

<?php algo(2) ?>

Expected output


4

(In a newline )


I don't know how to make questions for javascript yet


Als Antwort auf jupa poma

Re: sample for php and javascript question

von Richard Lobb -

Hi Jupa,

Good to know that the php question is working. Thanks for helping out, Nils. It sounds like I'd better improve the documentation and/or the error message with regard to the need to use adaptive mode for all CodeRunner questions.

I'm on leave at present with only limited internet capabilities and using only a cellphone, so I can't give very full answers to questions. I'll be back on line properly next week. In the meantime though here are some tips for writing JavaScript questions.

  • Assuming you're using a standard Jobe server as a sandbox (either our default one or a standard github install), JavaScript code is run using nodejs.
  • There is a nodejs question type but it isn't included in the default CodeRunner install. As a Moodle administrator, use Moodle's question import capability to import the MoodleXML questions in the file .../question/type/coderunner/db/uoc_prototypes.xml. Then, when creating a new coderunner question, you should be able to select nodejs as a coderunner question type (where you were selecting php before).
  • The nodejs question type is very similar to the php question type in that it just runs the student code followed by the test code for each testcase (but without the complication of '<? ... >',  of course).

Hope that's enough to get you going.

Richard

Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von jupa poma -
Hi, 

everything works fine with the import , my fault , I should have read all the documentation 

thanks

Als Antwort auf jupa poma

Re: sample for php and javascript question

von Sayee Krishnan -

By trying the same code i got error.I have enclosed the screen shot of the error

Anhang Screenshot from 2017-01-18 12-19-59.png
Als Antwort auf Sayee Krishnan

Re: sample for php and javascript question

von Richard Lobb -

Hi Sayee

The problem here is with the use of the "<?php" and "?>" tags. The template for the built-in PHP question type is currently

{{ STUDENT_ANSWER }}

define('SEPARATOR', '##');

{% for TEST in TESTCASES %}
{{ TEST.testcode }};
{% if not loop.last %}
echo SEPARATOR;
{% endif %}
{% endfor %}
@17943918#@>

For this to work, the student answer must start with <?php but should not include the closing tag. The test code should not use either opening or closing tags.

I think the template that Jupa was using was probably a simple per-test template (i.e. not a combinator). Something like

{{ STUDENT_ANSWER }}
{{ TEST.testcode }}

The documentation for the PHP question type is wrong, sorry. It applies to the above template not the current version.

Richard

Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von Sayee Krishnan -

Sorry I can't understand please give me a clear explanation.Can you update with sample PHP programs with suitable test cases.

Thank you.

Als Antwort auf Sayee Krishnan

Re: sample for php and javascript question

von Richard Lobb -

Sorry, it appears there's a bug in the PHP question type template. I'm on holiday at present and will push a fix next week. But if you want to fix your own local copy, change the template line

echo SEPARATOR;

to

echo SEPARATOR . "\n";

With that change in place, the following question should work fine:

Question: Write a function double($n) that returns twice the value of its parameter $n. Your answer should begin with "<?php" but should NOT include the closing "?>" tag.

Sample answer: 

<?php
function double($n) {
    return 2 * $n;
}

Test case 1:

echo double(-11);

Expected 1:

-22

Test case 2:

echo double(17);

Expected 2:

34
Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von Sayee Krishnan -
I have enclosed the screenshot of the error. Do check and reply as soon as possible. What next i can do to rectify this problem.
Anhang php.png
Als Antwort auf Sayee Krishnan

Re: sample for php and javascript question

von Richard Lobb -

This looks like a broken template. With the fix to the built-in PHP question type above, my output from the double question looks like the following:

A correctly working double question in php


Could you click the Customise checkbox and copy and paste the template into your reply, please.

I'm also puzzled that your browser appears to be trying to process the '<' in the separator string as if it were an opening tag, which shouldn't happen because the '<' character should have been converted to an HTML entity ('&lt;'). Is it possible you're using either a very old version of CodeRunner or a very old Moodle system?

Richard

Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von Sayee Krishnan -
This was my template code.If this is not a correct template means update me with the right code.

{{ STUDENT_ANSWER }}

define('SEPARATOR', '##');

{% for TEST in TESTCASES %}
{{ TEST.testcode }};
{% if not loop.last %}
echo SEPARATOR . "\n";
{% endif %}
{% endfor %}
@17943918#@>
Als Antwort auf Sayee Krishnan

Re: sample for php and javascript question

von Richard Lobb -

That's a seriously broken template. And the template for your Java program in another thread is also seriously broken. It looks like someone has edited the built-in prototype questions (BUILT_IN_PROTOTYPE_java_program etc). That's not a good idea. Even if you know exactly what you're doing it's much better to create new prototypes than edit the built-in ones, because every upgrade replaces the built-in ones and you'll lose any changes you've made. If you don't know exactly what you're doing it's generally catastrophic.

I suggest you pull the latest version of CodeRunner (V3.1.2 - pushed yesterday) and go through the usual version upgrade process. That will replace all the built-in prototypes so you should be able to write questions using them. Please don't edit or copy those built in prototypes. If you need a different template you can just create a new question of one of the existing types, then customise it as necessary.

Richard

Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von Sayee Krishnan -

Sorry I cant able to update you with my coderunner version, i didn't install in our department.Is any other possibility to rectify the problem.

This discussion is being continued by email.

(Edited by Richard Lobb - original submission Sunday, 29 January 2017, 12:21 AM)

Als Antwort auf Richard Lobb

Re: sample for php and javascript question

von Stefan Simic -
I have version 3.2 and here is how looks like my customisation template:

{{ STUDENT_ANSWER }}


define('SEPARATOR', '#<ab@17943918#@>#');


{% for TEST in TESTCASES %}

{{ TEST.testcode }};

{% if not loop.last %}

echo SEPARATOR;

{% endif %}

{% endfor %}


I did example like your but i have error

Expected 3 test results, got 1. Perhaps excessive output or error in question?

What should i do mr. Richard?

Anhang php2.jpg
Als Antwort auf Stefan Simic

Re: sample for php and javascript question

von Richard Lobb -

The template for the PHP question type seems to be broken. I'll look into how and when this happened but for now the fix is to edit the built-in prototype for the PHP question type (that is, the question called "BUILT_IN_PROTOTYPE_php" in the System > CR_Prototypes category) , replacing the line

define('SEPARATOR', '#<ab@17943918#@>#');

with

define('SEPARATOR', "#<ab@17943918#@>#\n");

Sorry about the bug; thanks for reporting it.

Richard