Problem Structure ================= Problems are a collection of a problem overview (or introduction), a question, and a solution. All problems are contained within an element with a class of "problems". Single Problems *************** The basic structure of a problem looks something like this (indents will be appropriate for copy and paste): .. code-block:: html

The exact elements that you use aren't important (they could be divs or paragraphs or something else entirely); all that matters is that they have the proper classes ("problem", "question", and "solution"). When defining the various parts of the problem, it will be necessary to refer to the variables you defined in the vars block. When defining the introduction, question, and solution, you can always refer to previously-defined variables with a ```` block; for the full list of formatting options (which are all available when defining the introduction and question), see the Formatting section of this wiki. Note on ``div class="problems"`` and ``p class="problem"`` ---------------------------------------------------------- You will see that at the top, we have a ``
`` markup. This is a wrapper which contains all the code that generates the problem - the question, the solution, the hints, multiple types of problems, everything except globally declared variables. In contrast, the ``

`` markup indicates that you are generating the intro or overview part of the problem. We want to use the class ``"problem"`` here for consistency but you can can think of it as "introduction" or "overview" or "needed info." Problem or Introduction ----------------------- The problem overview/introduction is optional and is defined with a class of "problem." It is mainly useful for word problems or any kind of problem that has important text or information that isn't explicitly part of the statement of the question. For example, a Physics problem may describe the situation and the various objects in the world before asking about a certain quality of a certain object. You could also put information in after the question if you want to provide clarity on how to answer the question. For example: .. code-block:: html

Express DECIMAL as a fraction.

(Extra Info: You can express this as any fraction - you don't have to "reduce to lowest terms" for the correct answer)

will let the user know what kind of answer is acceptable. If you are doing this, ``extra-info`` can be used for consistency. Question -------- The question is required and is defined with a class of "question". At the moment, the question is appended directly after the problem and is formatted the same, although this may change depending on the system. We provide these guidelines for how to choose the problem overview content and question content, but they are ultimately left at the discretion of the exercise author. The contents are not handled or interpreted in any particular way. Solution -------- Unlike problem introductions and questions, solutions do have a very specific form of markup. Like introductions and questions, it is the class name ("solution") which matters, not the element type; however, the content of the solution element is very important and is used as the basis for validating the user's input. For example, a valid solution that is dynamically-generated from a previously-created variable would be: .. code-block:: html

round(DIST1)

The user would then need to enter a number into the fill-in-the-blank form that matches the ``DIST1`` variable, rounded to the nearest integer. Multiple Problem Structure ************************** While it's totally possible that you might create an exercise with a single type of problem, it's very likely that you'll want to provide students with multiple styles of problems to challenge them. You will recall that the problem section of an exercise looks like this: .. code-block:: html

When building an exercise with multiple problems, the problems part of the code will look like: .. code-block:: html

So all the problems exist between the ``
`` wrapper and each different type of problem should have its own unique ID (examples below). Thankfully, you won't have to re-write the entire problem from scratch. You'll only have to write the new portions of the problem that differ from the original. OR: If you are doing word problems and you do have similar problems that have completely different structures (e.g. multiplication word problems involving money and multiplication word problems involving objects), then this structure also allows you to change everything within unique problem ID: variables, overview, question, solution, hints, everything. Let's go through each of these two examples of create multiple problem. Expanding / Extending a base or core problem -------------------------------------------- For expanding and extending an existing problem, the way you do it is by adding a unique ID to one of your problems and then referencing it from subsequent problems using a ``data-type="ID"`` attribute. For example one problem could ask for total distance travelled, another could ask for how long it took the travel the distance, etc. In the following markup we create two types of problems. One is the base or core problem (with the ID of "original") and the other is the problem that inherits from the original. .. code-block:: html

Ben traveled by CAR1 at an avg speed of SPEED1 mph.

He also traveled by CAR2 at an avg speed of SPEED2 mph.

The total distance covered was DIST miles for TIME hours.

How many miles did Ben go by VEHICLE1? (Round to the nearest mile.)

round(DIST1)

How many miles did Ben go by VEHICLE2? (Round to the nearest mile.)

round(DIST2)

Note how the second problem doesn't provide a problem definition. This problem definition is inherited directly from the original problem when we put in ``data-type="original"`` next to "vehicle-2-distance." Any markup provided by a subsequent problem will override the original. For example providing a "question" in a follow-up problem will override the "question" coming from the original. Using this technique you can easily generate many different styles of problems with only minimal amounts of typing. In general, we would like exercises to be as modular as possible, so consider creating multiple separate exercises unless the problems you are considering are fundamentally very similar. Similar Problems, Completely Difference Structures -------------------------------------------------- There are times where you will want two types of problems in the same exercise that share nothing in common, not even variables. The following is the basic layout for an X problem, X structure exercise (This is everything between the ``
`` tags: .. code-block:: html
randRange( 3, 12 ) randRange( 2, 12 )

A scarf costs $NUM_1. You buy multiple scarves.

How much would AMT_1 scarves cost?

NUM_1 * AMT_1

This is a multiplication question.

The answer is NUM_1 * AMT_1 dollars.

randRange(2, 9) randRange(2, 12)

Sally is CHILD_AGE years old. Her mom is PARENT_MULT times older.

How old is Sally's mom?

PARENT_MULT * CHILD_AGE

"Times older" is a clue word for multiplication.

Sally's mom is PARENT_MULT * CHILD_AGE years old.

As you can see, with this structure, each problem type is a completely self contained unit, where each problem type has defined its own variables, questions, solutions and hints. There is more on Multiple Problems at: [More on Multiple Problems](https://github.com/Khan/khan-exercises/wiki/More-on-Multiple-Problems)