This blog post will walk you through some basic examples of building Submission Correctness Tests (SCTs) so that you can begin to create your own interactive courses on DataCamp. Together we will walk through six basic functions and see how they work. You will be able to see how to write SCTs in the R code chunks and follow along in the interactive exercises to see their output. We will be using the same exercise for each example, but you will notice some changes along the way as we improve our SCT code in the background! The correct answers are already filled in for you, but try to mess around with them to see how the SCT performs.
First, let’s introduce the exercise we will be working with today. We have created an exercise below with three separate instructions. We are asking the student to do the following:
-
Create a vector called
my_vect
containing 1 through 5. -
Take the mean of
my_vect
and assign it to a variable namedmy_mean
. Use themean()
function. -
Use
my_mean
to compute the sum of squares ofmy_vect
. Use thesum()
function.
# Create a vector called my_vect containing 1 through 5
my_vect
The code chuck above represents the solution to the exercise. Now we need to build some tests to make sure our students are entering the correct response. Let’s make some SCTs!
The first function that every exercise should have is called the success_msg()
. Within this function, you will write the message that you want to appear when the student gets the problem correct. Remember our problem from above? We’ve added a success message behind the scenes.
# sct code
success_msg("Nice work! Success messages are a great way to keep users engaged even after the exercise is over. Try to encourage them to play around in the ...read more
Source:: r-bloggers.com