## Quiz

### How can I have a student enter a fraction as an answer?

How can I have a student enter a fraction as an answer?

Note: I have this sneaking suspicion that some other elementary or middle school math teacher has wrestled with a lot of these issues already, but they are all coming up for the first time to me. If you know someone who has used Moodle in this capacity already and may have some tips and tricks for this kind of use, please let me know. Thanks!

I need to provide the flexibility for my students to enter fractions as an answer, rather than simply provide multiple choice entries. I tried combining LaTeX with the cloze question type, and that really confused Moodle. I know I could pull it off if I could require multiple answer fields in a calculated question. Then, I could do something like this:

Enter your answers in the blanks below according to these labels: $$whole \frac { numerator } { denominator }$$
 Whole: ___________ Numerator: ___________ Denominator: ___________

Requiring them to enter the fraction has a lot more power, since I can check for common errors and oversights and provide specific feedback. If I give them multiple choice responses, I don't have nearly the flexibility for error analysis.

Ideas?

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?

You could use Joseph Rezeau's Regular Expression Short Answer question type. You (teacher) will have to learn to write the regular expressions (which are used for the answers), and you'll need to explain to your students how you want them to input mixed numbers in a linear format (e.g., as a whole number followed by at least one space and then a proper fraction reduced to lowest terms). With regular expressions, you will be able to accept either mixed numbers or improper fractions as valid answers, and you'll be able to give some fairly good feedback (e.g., you can create regular expressions that detect when they haven't reduced to lowest terms). I don't think students should be writing LaTeX.

Regular expressions can be used for simple numbers (fractions, mixed numbers, decimal numbers, and probably extremely simple algebraic expressions). For anything more complicated, you'll need a decent computer algebra system.

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?

Thank you, I'll look into such a thing. I had hoped for a bit more natural input method, but linear textual adaption could work.

By the way, I wasn't trying to set it up so that the students entered answers in LaTeX, I tried to set up a cloze question so that the answer blank appeared in the LaTeX output, instead of passing a static value. I should have realized right away that this wouldn't work, since LaTeX is basically an inline .gif maker. You certainly can't have an input control as part of a .gif, but that's ultimately what I'm after: Something that looks like a fraction, with a spot for them to enter their response in an intuitive way. Like this:

Someday, I'll code such a thing, but right now I'm balancing too much stuff.

Is RegEx my best approximation for this?

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?

Hi Matt,
Ah, now I see what you're trying to do. It would be nice if you could do that with cloze. I haven't had much success getting cloze questions to lay out the way I want. If you figure out how to do it, let us know

Meanwhile, you could try Regex, but maybe it's not worth the extra effort if all you need is fractions and mixed numbers. Then plain short answer will be adequate, as Pierre suggests.

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
Do you mean doing something like this in cloze questions?

I thought the problem was with the calculation rather than with the layout.

Average of ratings: Useful (1)
Re: How can I have a student enter a fraction as an answer?

\frac{34}{34}

Average of ratings: Useful (1)
Re: How can I have a student enter a fraction as an answer?
You could use simple short answer question type and you use as much answers as there are good responses if you allow simplified fractions i.e 1/2, 2/4, 4/8 or not.
You will need to create a set of questions to cover the range of values or difficulty level.
Here a simple example:
Express 7,75 as a fraction different from 7 75/100
Put a space between the whole number and the fraction i.e. 7 75/100

7 3/4
7 6/8
7 9/12
7 12/15
etc.

Pierre

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
If I may add to and complicate a little bit this solution, in one of my experiments with cloze questions I got a similar effect while preserving a desired input layout by adding a block of html with input fields organized as desired and some javascript that copied the text from the input fields into the question's short-answer field. And so input was formatted in one way and the string that was actually matched against the predetermined answers was formatted in another.

Itamar

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?

What you described in both your posts is exactly what I'm after. It is more an issue of layout. If you have any code that demonstrates how to do this effectively, I would really appreciate it.

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
This layout simply uses a table (with border=0) but of course as a question it can only work with one correct answer.

As for the more flexible solution give me a sec to find it (or reinvent it, whichever comes first). I'll be right back.

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
Okay I'm back. I couldn't find it so I created a quick simple example of the fraction exercise. You may notice in the images below that after submitting the answer (in a quiz) the values in the input fields are not preserved. They may be restored with just a little bit more work so if you wish to use this solution I can add this feature. By the way if you try it it won't work in the pop-up of the preview mode, only in a quiz.

In this example the values from the input fields are copied into the shortanswer field after the denominator loses focus, so the order of entering the values is important. Again, this is just a quick example and there is much more that can be done to make it more user-friendly.

Note that in the code the 'nnnnn' should be substituted with the name of the shortanswer field. So first you need to create the question like that and then open the question in preview mode, open the page html source and look up the name. Not very elegant but if it gets you what you need it is worth it.

Let me know if you need any other details.

Average of ratings: Useful (2)
Re: How can I have a student enter a fraction as an answer?
One problem with this solution is that there seems that there are two ways to enter the value which is confusing for the student.

Pierre

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
I agree but as I suggested this example is quite quick and dirty. The actual question can be laid out in such a way that most if not all confusion is eliminated.

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?

You have officially achieved rockstar status! That is exactly what I was after. I'll try to figure out a way to hide the official answer box from view, tweak the code so that it runs just prior to submission, and exploit the full spiffiness of RegEx to lend power to answer parsing. When I have a final working solution, I'll post it here (probably in the Fall, looking at my schedule).

Thanks to everyone for all your help!

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
The official answer box can be hidden by placing it in a a div tag with style="visibility:hidden".

The image below shows that in a hidden kind of way. For each row there is an official answer box in the right most column which you cannot see because it is hidden so you'll have to take my word for it.

Notice the buttons which allow a student to validate an answer, display the correct answer and reset the fields. The buttons call javascript functions and pass relevant parameters to them. The functions do not reside in the question but rather in the "back-end" of a description question (which otherwise is empty) so that they can be called by multiple questions in the same quiz page without code duplication and conflicts.

This question was used for practice so the quiz assessment was not necessary in that case. Disabling the validation and display buttons can turn the question into formal assessment. Or disabling only the display button may allow a student to keep trying until the answer is figured out or time's up.

The image shows the question view after clicking 'Validate' which indicates a wrong answer in line 6.

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
I did not realize that the openness of the Cloze question allows inclusion of such modifications.
Using a description question to include javascript is quite an idea.
This remember me a work-around that I used on WebCT to synchronize numerical data between different calculated questions.

Pierre

Average of ratings: -
Re: How can I have a student enter a fraction as an answer?
One more thing An alternative way to access the official answer box without tracking its name is by placing it in a known position relative to an identified html element in the question and navigating the DOM hierarchy.

Average of ratings: -