Exercise 13: Returning from a Function

Let's test your ability to return data from a function.

Problem Statement

Implement a function evenOdd that takes a vector of numbers as input and returns a vector where each element of the output vector has the string “even” or “odd” depending on the corresponding element of the input vector.

Input

A testVariable containing the vector to be tested.

Output

A vector where each element is either “even” or “odd” depending on the state of the corresponding element of the input testVariable vector.

Sample Input

testVariable <- c(78, 100, 2)

Sample Output

"even" "even" "even"

Test Yourself

Write your code in the given area. If you get stuck, you can look at the solution.

Press + to interact
evenOdd <- function(testVariable)
{
output <- vector("character", 0) # initializing an empty character vector
# Write your code here
return(output)
}