Skip to content

Types of Questions

Sean Kross edited this page Jun 3, 2016 · 3 revisions

ATTENTION!

This documentation is deprecated. For the latest version of the swirlify documentation please visit: http://swirlstats.com/swirlify

The swirlify package supports writing 8 types of questions. As discussed in Adding Questions to a Lesson questions are made up of key-value pairs. Many of these key-value pairs are shared between types of questions. Let's review the shared key-value pair types:

  • Class
    • This key-value pair specifies the type of the question. The course author should not modify this.
  • Output
    • The value of this key-value pair should be a string of text which is displayed to the student. This string usually asks a question to a student or instructs the student about how to answer the question. It's common to surround this string with quotation marks.
  • CorrectAnswer
    • The swirl package provides a function called skip() which allows the student to skip a question by having swirl enter the correct answer for that question. Therefore CorrectAnswer is an R expression that should correspond to a correct answer to the question. The CorrectAnswer expression will be submitted to swirl if a student uses skip().
  • AnswerTests
    • The value of this key-value pair is an R expression that must evaluate to TRUE if the answer to the question is correct or FALSE is the answer to the question is incorrect. For a comprehensive understanding of how answer testing works execute library(swirl);?AnswerTests in your R console. If you just want to start writing a swirl course as quickly as possible you should emulate the questions in Question Examples.
  • Hint
    • This key-value pair is very similar to Output. The value is a string of text that is only displayed to the student if their answer to the question is incorrect.

There other key-value pairs that are specific to certain questions types and they will be discussed later in this document.

Question Types

Examples of each question type can be seen in Question Examples.

Message Questions

Message questions display a string of text in the R console for the student to read. Once the student presses enter, swirl will move on to the next question.

Message questions can be appended to the end of a lesson.yaml file with the function wq_message() which will append the following:

- Class: text
  Output: put your text output here

Multiple Choice Questions

Multiple choice questions (or multiple guess questions as my high school math teacher used to say) display a string of text in the R console for the student to read. The student is then presented with a number of choices where each choice is numbered. The student must enter the correct number into the R console to get the question right. If the student gets the question wrong the numbers and choices are shuffled and the student gets another attempt. There is no limit on the number of choices a course author can present to a student, but we recommend limiting the number of choices to six.

Multiple choice questions can be appended to the end of a lesson.yaml file with the function wq_multiple() which will append the following:

- Class: mult_question
  Output: ask the multiple choice question here
  AnswerChoices: ANS;2;3
  CorrectAnswer: ANS
  AnswerTests: omnitest(correctVal= 'ANS')
  Hint: hint

The AnswerChoices key-value pair must be a collection of answer choices with each choice separated by a semicolon.