Solution Review: Creating Functions

In this review, we provide a detailed analysis of the given problem.

Solution: Creating a Function

Press + to interact
evenOdd <- function(testVariable)
{
if(testVariable %% 2 == 0)
{
cat("even")
} else
{
cat("odd")
}
}
# Driver Code
evenOdd(78)
cat("\n")
evenOdd(67)
cat("\n")
evenOdd(1)

Explanation

Create a function using the following syntax:

evenOdd <- function(testVariable)
{
   <Conditional Block>
}

The function takes an argument testVariable and accordingly performs some tasks on it.