# a function that generates a random question
random_question <- function() {
number <- round(rnorm(1, 30, 10), 0)
rand_prompt <- paste('Is', number, 'an even number?')
# using create_question inside the function helps to ensure correct class
q <- create_question(
prompt = rand_prompt,
add_choice('Yes, it is even', correct = number %% 2 == 0),
add_choice('No, it is odd', correct = number %% 2 != 0)
)
return(q)
}
# create a quiz with a question bank of 20 randomly generated questions
quiz <- create_quiz(
create_question_random(.f = random_question, n = 20)
)
Run the code above in your browser using DataLab