...

/

Solution Review: if/else Statements

Solution Review: if/else Statements

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

Solution: Using a Combination of if and else

Press + to interact
R
testVariable <- 45
if(testVariable %% 3 == 0 && testVariable %% 5 == 0)
{
cat("foo bar")
} else {
if(testVariable %% 3 == 0)
{
cat("foo")
}
if(testVariable %% 5 == 0)
{
cat("bar")
}
}

Explanation

We first check whether the testVariable is a multiple of both 33 and 55 ...