In a BlanksChallenge, a student completes code to match the displayed output. A student can see two variations of a BlanksChallenge: one in which the student is presented with a set of code snippets to choose from — further referred to as a tap view — and one in which the student needs to type the missing piece of code — further referred to as a typing view.

Here's an example of a tab view on mobile:

And this is how the corresponding typing view looks on desktop:

When to use a BlanksChallenge?

BlanksChallenges are the ideal choice for testing the student's knowledge of specific syntax: a function, a function argument or a package name.

Note that a BlanksChallenge cannot generate a plot as an output. To learn about testing plotting knowledge, go to this article.

Authoring a BlanksChallenge

The anatomy of coding Practice exercises, such as OutputChallenges, is described in this article. This section here describes the specific syntax to write a BlanksChallenge in the Teach editor.

To learn about using DataCamp's Teach editor to create practice content, take a look at this article.


The BlanksChallenge template contains an optional context block. When and how to use the context block is described in the article on Practice exercise anatomy.

Pre-challenge code

At the bottom of the BlanksChallenge template you'll find the pre-challenge code block. You'll use this block to prepare the workspace, allowing the exercise code to run properly. So this is the place to be for loading packages and datasets or creating datasets on the fly.

Exercise code and variables

A code block provides a placeholder to generate code for a BlankChallenge. That makes sense, right? By including references to variables specified in the variables block, you create variations on the code. In the Teach editor, variables are referred to by placing the variable name between double curly brackets: {{ }} . To indicate that a variable should be presented as a blank, prepend the variable name with a _ (see the {{_fun1}}  in the example code below).

Note that var, fun, function or actual function names are not accepted as a valid reference. These will result in a mobile Preview error, such as Unexpected token ).

If a student encounters this challenge, the backend will randomly choose a value for  var1, while fun1  will be presented as a blank.

The BlankChallenge template contains multiple code blocks. You can use additional code blocks to specify several code templates. When generating a view for the challenge, the backend will start by randomly selecting one of these code blocks.


In addition to variables, distractors are mandatory for BlanksChallenges. Distractors are code snippets that could challenge the student's knowledge of relevant syntax, and are typically similar to the correct value of the variable. Note that distractors are not used by the backend to generate code; therefore, distractors don't have to lead to functional code.
In the example below, the value of var2  is used as a distractor for var1 ; likewise, the values of var1  that are not selected to generate the code, are used as distractors for var2 . Finally, 3 distractors are specified for fun1 .

Final note

Now that you've seen the details of creating a BlanksChallenge, take another look at the examples provided at the beginning of this document. Do you see how they relate to the code mentioned throughout the document? Can you tell which code block was used by the backend to generate the exercise code?

Now it's your turn! Go to the Practice pool you are working on and make some marvelous BlankChallenges!

Did this answer your question?