Skip to content

Adding Questions to a Lesson

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

ATTENTION!

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

Time to add some questions to your lesson! Make sure that before you start adding questions you've started a new lesson using new_lesson() or you've made swirlify aware of the lesson you wish to work on using set_lesson(). You should write lessons using a text editor and an R console simultaneously. RStudio provides the perfect environment for writing swirl courses.

Lesson Structure

Lessons are sequences of questions that have the following general structure:

- Class: [type of question]
  Key1: [value1]
  Key2: [value2]

- Class: [type of question]
  Key1: [value1]
  Key2: [value2]
...

Each question starts with a Class that specifies that question's behavior inside of swirl. To find out more about how different kinds of questions behave see Types of Questions. What follows the class is a set of key-value pairs that will be used to render the question when a student is using swirl.

The Meta Question

When I created the How to use pnorm lesson in the Normal Distribution Functions in R course my text editor displayed a lesson.yaml file that contained the following:

- Class: meta
  Course: Normal Distribution Functions in R
  Lesson: How to use pnorm
  Author: your name goes here
  Type: Standard
  Organization: your organization's name goes here
  Version: 2.3.1

This is a meta question that must be the first question in every swirl lesson. This meta question is not shown to the student, but it contains information that swirl requires.

  • Class is set by swirlify and should not be modified.
  • Course must correspond to the name of the course the lesson is in.
  • Lesson must correspond to the name of the lesson.
  • Author should be the name of the author of the course.
  • Type must be either Standard or Coursera. If you're developing a swirl course in conjunction with a Coursera course see Linking a swirl Course with a Coursera Course for more information. Otherwise just use Standard.
  • Organization should be the name of the author's organization if there is one. Otherwise this can be blank.
  • Version is set by swirlify and should not be modified.

Writing Questions Using wq_ Functions

Now that you've made swirlify aware of which lesson you're working on and you've set up the meta question you can now start adding swirl questions! You should add questions using the functions swirlify provides which follow the schema wq_[type of question](). The wq_ portion of the function schema is an abbreviation for write question. If you're using an R console with tab completion (like in RStudio) then on a western English keyboard it should be easy to type W then Q then Tab in order to get a list of all the question types you can add to the lesson you're working on.

The most simple kind of question is a message question. A message question will show the user a string of text and prompt them to press enter. To add a message question simply type the following into your R console:

wq_message()

After executing wq_message() my How to use pnorm lesson.yaml now looks like this:

- Class: meta
  Course: Normal Distribution Functions in R
  Lesson: How to use pnorm
  Author: your name goes here
  Type: Standard
  Organization: your organization's name goes here
  Version: 2.3.1

- Class: text
  Output: put your text output here

You can replace put your text output here with whatever text you want the student to see. You should continue adding questions to your lesson by using the wq_ family of functions. A wq_ function will always append a question to the end of the lesson.yaml file you're working on. To find out more about other question types see Types of Questions.