question_numeric: Number question

View source: R/question_numeric.R

question_numericR Documentation

Number question

Description

Creates a tutorial question asking the student to submit a number.

Usage

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
)

Arguments

text

Question or option text

...

Answers created with answer() or answer_fn(), or extra parameters passed onto question().

correct

For question, text to print for a correct answer (defaults to "Correct!"). For answer, a boolean indicating whether this answer is correct.

incorrect

Text to print for an incorrect answer (defaults to "Incorrect") when allow_retry is FALSE.

try_again

Text to print for an incorrect answer (defaults to "Incorrect") when allow_retry is TRUE.

allow_retry

Allow retry for incorrect answers. Defaults to FALSE.

value

Initial value.

min

Minimum allowed value

max

Maximum allowed value

step

Interval to use when stepping between min and max

options

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.

tolerance

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.

Value

Returns a learnr question of type "learnr_numeric".

See Also

Other Interactive Questions: question_checkbox(), question_radio(), question_text(), quiz()

Examples

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_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
)


learnr documentation built on Sept. 28, 2023, 9:06 a.m.