Avoid pre-selected answers in learnr multiple choice questions

How can you ensure learnr multiple-choice questions do not have a default answer selected? For example, the code below...

```{r KC-1, echo=FALSE}
question("TRUE or FALSE: My R Scripts can look sloppy as long as RStudio is able to run it.",
  answer("TRUE", message = "Not quite. Think about all the *computers* you are creating computer programs for."),
  answer("FALSE", correct = TRUE, message = "That's right. You should strive to make your computer programs should be interpretable by other humans as well."),
  allow_retry = FALSE
)
```

generates this...
image

, and I do not want to have FALSE (or any other option) to be pre-selected.

set questions type="multiple" ?

I still only want a single option to be the correct answer (so type="single" or type="learnr_radio"). I just want it so FALSE isn't pre-selected.

oh !
it seems 'FALSE' is some special value, so this would work...

```{r KC-1, echo=FALSE}
question("True or False: My R Scripts can look sloppy as long as RStudio is able to run it.",
  answer("True", message = "Not quite. Think about all the *computers* you are creating computer programs for."),
  answer("False", correct = TRUE, message = "That's right. You should strive to make your computer programs should be interpretable by other humans as well."),
  allow_retry = FALSE
)
2 Likes

If you change the case of the options to "True" and "False", the "FALSE" option won't be inadvertently selected initially.

```{r KC-1, echo=FALSE}
question("TRUE or FALSE: My R Scripts can look sloppy as long as RStudio is able to run it.",
  answer("True", message = "Not quite. Think about all the *computers* you are creating computer programs for."),
  answer("False", correct = TRUE, message = "That's right. You should strive to make your computer programs should be interpretable by other humans as well."),
  allow_retry = FALSE
)
```

This will be fixed shortly in learnr, see rstudio/learnr#515.

1 Like

That worked! Thanks a ton.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.