Quizzes with Webexercises and Quarto

Quarto
Webexercises
Teaching
Author

Joaquim Puig

Published

April 4, 2023

Example of a test with quarto+webexercises

Using the wonderful {webexercises} package you can create interactive web pages for checking your knowledge. These are a set of widgets that allow for different type of questions, and can be used as inline content.

library(webexercises)

According to the information on this bug, “To use webexercises with quarto you need to add the css and js files to the format html option in the _quarto.yml file.” For example, mine is

title: "Quizzes with Webexercises and Quarto"
author: "Joaquim Puig"
format:
  html:
    css: include/webex.css
    include-after-body: include/webex.js
date: "2023-03-01"
draft: true
categories:
  - Quarto
  - Webexercises
  - Teaching

and now you can use the functions in the package for revision questions.

Note
  • solutions are not hidden so don’t use it in real exams.
  • there are no permutations: answers appear in the same order as they are created. Correct answers will simply highlight. Of course, you can do as many permutations as you like.
  • The counter of correct questions is for the whole webpage (see example below)

Example of questions with webexercises

Try the following test:

  • Numeric questions How much is 2+3? .
  • Multiple Choice Which is the capital city of Barbados?
  • True or False Quarto is very cool .

Grade (more questions at the bottom): .

This can be obtained through the following markdown with inline r comments:

- **Numeric questions** How much is 2+3? `r fitb(2+3)`
- **Multiple Choice** Which is the capital city of Barbados? 
  `r mcq(c(answer="Bridgetown", "Georgetown", 
           "Kingston", "Bridgerton"))`
- **True or False** Quarto is very cool `r torf(TRUE)`.

**Grade**: `r total_correct()`.

Longer tests

For longer tests you can directly use R code and not inline code

What is the name of the main character in ‘Mansfield Park’?
Who is the author of Mansfield Park?
Where is the main setting of Mansfield Park?
Who is Fanny Price’s wealthy uncle in Mansfield Park?
Who is Fanny Price’s love interest in Mansfield Park?

It is important that you write that results are ‘asis’ in the code:

#| eval: false
#| results: asis

and the questions are defined as follows:

# Define the questions
q1 <- "What is the name of the main character in 'Mansfield Park'?"
q2 <- "Who is the author of Mansfield Park?"
q3 <- "Where is the main setting of Mansfield Park?"
q4 <- "Who is Fanny Price's wealthy uncle in Mansfield Park?"
q5 <- "Who is Fanny Price's love interest in Mansfield Park?"

# Define the answer choices
q1_choices <- c("Elizabeth", "Mary", answer= "Fanny", "Catherine")

q2_choices <- c( answer= "Jane Austen", "Charlotte Bronte", "Emily Bronte", "Agatha Christie")

q3_choices <- c("London", "Bath", "Manchester",  answer= "Mansfield Park")

q4_choices <- c( answer= "Sir Thomas Bertram", "Mr. Price", "Mr. Crawford", "Mr. Rushworth")

q5_choices <- c( answer= "Edmund Bertram", "Tom Bertram", "Henry Crawford", "William Price")

cat(q1,longmcq(q1_choices))
cat(q2,longmcq(q2_choices))
cat(q3,longmcq(q3_choices))
cat(q4,longmcq(q4_choices))
cat(q5,longmcq(q5_choices))