formula questions - distribute values

formula questions - distribute values

by Ahmad Amer -
Number of replies: 1
Salam,
In the distribution process, how do I order the program to automatically give me a tenth place or a unit in my answer?
For example, in the provided screenshot (give me a 40 or a 2 as of 42 in my answer boxes OR a 10 and a 2 as of 12 in one of my answer boxes)
what I basically want is to provide an answer in some of my boxes to give the students a head start on the answer

Thanks Dominique
Average of ratings: -
In reply to Ahmad Amer

Re: formula questions - distribute values

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Salam Ahmad,

To put the value of a variable, say x, defined in the variables, into the first answer box, place the following code in the HTML of the question text:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $("input.formulas_number:eq(0):text").val({x});
    });
</script>

If you want to put a value in the second answer box, replace :eq(0) with :eq(1), etc. (index starts at 0).

If you want to put a constant value in an answer box, replace {x} with the value, for example 40 or 2.

If you want to put values in more than one box, repeat the line starting with $("input...