The "math question" module

15_-_math_question.png

This is the last and biggest bonus exercise for those of you interested in doing some module writing. In this exercise you should write the fashionable "math question" module, that does the following:

  • Any user visiting the /question path will get a simple add-two-numbers question, such as "What is 4 + 9?".
  • There is also a box for entering the answer, and a button for submitting.
  • If the answer is correct, a nice message is displayed and a new question is presented.
  • If the answer is not correct an error message is displayed, associated with the answer box.

There is no suggested solution, but here are some hints:

  • You will need hook_menu, and the drupal_form callback will be useful
  • The form element type #value will be useful for sending along the correct answer without showing it
  • The form element type #markup will be useful, too
  • You will need to use the t() function with a replacement parameter if you want to have dynamic numbers in the math question
  • Functions named FORM_ID_validate($form, $form_state) will be called automatically on form submission, to run any validation checks
  • The $form_state variable contains the form submissions, if you look at the right place
  • Check out the form_set_error function in the Drupal API reference

Good luck!