Creates a tutorial question asking the student to submit a number.
question_numeric(
text,
...,
correct = "Correct!",
incorrect = "Incorrect",
try_again = incorrect,
allow_retry = FALSE,
value = NULL,
min = NA,
max = NA,
step = NA,
options = list(),
tolerance = 1.5e-08
)Question or option text
Answers created with answer() or answer_fn(), or extra
parameters passed onto question().
For question, text to print for a correct answer (defaults
to "Correct!"). For answer, a boolean indicating whether this answer is
correct.
Text to print for an incorrect answer (defaults to
"Incorrect") when allow_retry is FALSE.
Text to print for an incorrect answer (defaults to
"Incorrect") when allow_retry is TRUE.
Allow retry for incorrect answers. Defaults to FALSE.
Initial value.
Minimum allowed value
Maximum allowed value
Interval to use when stepping between min and max
Extra options to be stored in the question object. This is
useful when using custom question types. See sortable::question_rank()
for an example question implementation that uses the options parameter.
Submitted values within an absolute difference less than or
equal to tolerance will be considered equal to the answer value. Note
that this tolerance is for all answer() values. For more specific answer
value grading, use answer_fn() to provide your own evaluation code.
Returns a learnr question of type "learnr_numeric".
Other Interactive Questions:
question_checkbox(),
question_radio(),
question_text(),
quiz()
question_numeric(
"What is pi rounded to 2 digits?",
answer(3, message = "Don't forget to use the digits argument"),
answer(3.1, message = "Too few digits"),
answer(3.142, message = "Too many digits"),
answer(3.14, correct = TRUE),
allow_retry = TRUE,
min = 3,
max = 4,
step = 0.01
)
#> Question: "What is pi rounded to 2 digits?"
#> type: "learnr_numeric"
#> allow_retry: TRUE
#> random_answer_order: FALSE
#> answers:
#> X: "3"; "Don’t forget to use the digits argument"
#> X: "3.1"; "Too few digits"
#> X: "3.142"; "Too many digits"
#> ✔: "3.14"
#> messages:
#> correct: "Correct!"
#> incorrect: "Incorrect"
#> try_again: "Incorrect"
#> Options:
#> min: 3
#> max: 4
#> step: 0.01
#> tolerance: 1.5e-08
question_numeric(
"Can you think of an even number?",
answer_fn(function(value) {
if (value %% 2 == 0) {
correct("even")
} else if (value %% 2 == 1) {
incorrect("odd")
}
}, label = "Is the number even?"),
step = 1
)
#> Question: "Can you think of an even number?"
#> type: "learnr_numeric"
#> allow_retry: FALSE
#> random_answer_order: FALSE
#> answers:
#> ?: "Is the number even?"
#> messages:
#> correct: "Correct!"
#> incorrect: "Incorrect"
#> Options:
#> min: NA
#> max: NA
#> step: 1
#> tolerance: 1.5e-08