R/quiz_me.R

#' IDA Quiz Me Function
#'
#' This function tests your data analysis knowledge. Check the questions on your work sheet and determine whether they are continuous, ordinal, or nominal.
#' @param question The number of the question you are answering (see the "Data Analysis Basics" work sheet)
#' @param answer Your answer. One of either "continuous", "ordinal", or "nominal".
#' @examples
#' quiz_me(question = 1, answer = "continuous")

quiz_me <- function(question = NULL, answer = NULL){
  if(is.null(question) == T & is.null(answer) == T){
    warning("\n\nYou must give the function a question number and an answer for it to work.\nFor example: quiz(question = 1, answer = my_answer)")
  } else if(is.null(question) == T){
    warning("\n\nYou must give the function a question number for it to work.\nFor example: quiz(question = 1, answer = my_answer)")
  } else if(is.null(answer) == T){
    warning("\n\nYou must give the function an answer for it to work.\nFor example: quiz(question = 1, answer = my_answer)")
  } else if(!(question %in% 0:8)){
    warning("\n\nYou must give the function a question number between 1 and 8 for it to work.\nFor example: quiz(question = 1, answer = my_answer)")
  } else if(question == 0){
    ifelse(tolower(answer) == "continuous", "Correct! Weight in kg is a continuous variable!", "Whoops! Not quite. Try again!")
  } else if(question == 1){
    ifelse(tolower(answer) == "continuous", "Correct! Age in years is a continuous variable!", "Whoops! Not quite. Try again!")
  } else if (question == 2){
    ifelse(tolower(answer) == "ordinal", "Correct! Age groups are ordinal variables!", "Whoops! Not quite. Try again!")
  } else if (question == 3){
    ifelse(tolower(answer) == "nominal", "Correct! Title is a nominal variable!", "Whoops! Not quite. Try again!")
  } else if (question == 4){
    ifelse(tolower(answer) == "nominal", "Correct! The political party you support is nominal!", "Whoops! Not quite. Try again!")
  } else if (question == 5){
    ifelse(tolower(answer) == "ordinal", "Correct! How much you like Manchester on a 1-5 scale is ordinal!", "Whoops! Not quite. Try again!")
  } else if (question == 6){
    ifelse(tolower(answer) == "continuous", "Correct! Height in cm is a continuous variable!", "Whoops! Not quite. Try again!")
  } else if (question == 7){
    ifelse(tolower(answer) == "nominal", "Correct! Dog/cat preference is a nominal variable! (and dogs is the right answer...)", "Whoops! Not quite. Try again!")
  } else if (question == 8){
    ifelse(tolower(answer) == "ordinal", "Correct! Dog/cat preference on a 0-10 scale is an ordinal variable!", "Whoops! Not quite. Try again!")
  }
}
jackobailey/IDA documentation built on May 7, 2019, 6:59 p.m.