Description Usage Arguments Examples
This S3 class should be instantiated and passed to the Question constructor. It will be used to verify the users' answer and also provide feedback when a given answer is incorrect.
1 | QuestionTester(tester_function, feedback_generator)
|
feedback_generator |
this argument is used to rovide relevant feedback
to the user. It can be either a simple |
tester_fun |
the function that will be called to verify the question answer.
It should only return |
1 2 3 4 5 6 7 8 9 10 11 | ## Instantiate a QuestionTester that tests for a character vector with a single
## "word" of length 5
## The feedback_generator generates some appropriate messages depending on the answer
t1 <- QuestionTester(
function(x){is.character(x) && length(x)==1 && nchar(x)==5},
function(x){
if(! is.character(x)) "that is no word"
else if(nchar(x) < 5) paste0(x, " has ", nchar(x), " characters and that is not 5")
}
)
q1 <- Question("Please give a word of length 5", t1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.