wiki:BoltTutorialExercises

Version 13 (modified by davea, 16 years ago) (diff)

--

Bolt Tutorial, part II: Exercises

Now let's add some exercises. The first one is conifer_ex1.php:

<?php
echo "Conifers are so named because:";
exclusive_choice(
    array(
        'They carry their seeds in cones',
        'They are cone-shaped',
        'They originated in the Coniceous era',
    )
);
?>

exclusive_choice() defines a multiple-choice question.

The exercises are added to the course file: Then edit conifer.php:

function intro_exercises() {
    return exercise_set(
        name('Intro exercises'),
        number(2),
        exercise(
            filename('conifer_ex1.php')
        ),
        exercise(
            filename('conifer_ex2.php')
        ),
        repeat(.3, intro_lessons(), REVIEW),
        repeat(.7, intro_lessons(), REVIEW|REPEAT),
        repeat(1, null, REPEAT|NEXT),
        refresh(array(7, 14, 28))
    );
}

...

return sequence(
    name('course'),
    intro_lessons(),
    intro_exercises(),
    pine_lessons(),
    id_exercises()
);

Start the course from the beginning. When you get to the exercise you'll see

You'll then see either

or

depending on whether you answered the question correctly.

Some notes:

  • In exclusive_choice(), the correct answer is always the first choice listed. Bolt randomly reorders the choices to remove any ordering effects.
  • The exercise page is used to generate both the exercise and the answer page.
  • If you look at your course history, you'll see that Bolt has stored your answers to the exercise, and your score, in its database.

Reviewing and repeating exercises

Suppose the student doesn't perform the exercise correctly, and you want to let them (or require them to) review the lessons and repeat the exercise? Bolt provides a powerful mechanism for this, called exercise sets. To illustrate this, first let's create a new exercise, conifer_ex2.php:

<?php
echo "
Check the correct statements.
";

inclusive_choice(array(
    array("Conifers drop their leaves in autumn", 0),
    array("All conifers have needle-like leaves", 0),
    array("Conifers carry their seeds in cones", 1)
));
?>

This exercise is a set of true/false questions; the 0/1 arguments indicate which are true.

Edit conifer.php to contain:

function both_lessons() {
    return sequence(
        name('both lessons'),
        lesson(
            name('Introduction'),
            filename('conifer_intro.php')
        ),
        lesson(
            name('Conifers and deciduous trees'),
            filename('conifer_decid.php')
        )
    );
}

function second_lesson() {
    return lesson(
        name('Conifers and deciduous trees'),
        filename('conifer_decid.php')
    );  
}

function exercises() {
    return exercise_set(
        name('exercise set 1'),
        number(2),
        exercise(
            filename('conifer_ex1.php')
        ),
        exercise(
            filename('conifer_ex2.php')
        ),
        repeat(.3, both_lessons(), REVIEW),
        repeat(.7, second_lesson(), REVIEW|REPEAT),
        repeat(1, null, REPEAT|NEXT),
        refresh(array(7, 14, 28))
    );
}

return sequence(
    name('course'),
    both_lessons(),
    exercises()
);

The course structure is now:

Attachments (5)

Download all attachments as: .zip