Challenge - 5 Problems
Arithmetic Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed arithmetic operations
What is the output of this R code snippet?
R Programming
result <- 5 + 3 * 2^2 - 4 / 2 print(result)
Attempts:
2 left
💡 Hint
Remember the order of operations: exponentiation, multiplication/division, addition/subtraction.
✗ Incorrect
The expression evaluates as 5 + 3 * (2^2) - 4 / 2 = 5 + 3 * 4 - 2 = 5 + 12 - 2 = 15.
❓ Predict Output
intermediate2:00remaining
Result of integer division and modulus
What is the output of this R code?
R Programming
a <- 17 b <- 5 cat(a %/% b, a %% b)
Attempts:
2 left
💡 Hint
Integer division %/% gives quotient, modulus %% gives remainder.
✗ Incorrect
17 divided by 5 is 3 with remainder 2, so output is '3 2'.
🔧 Debug
advanced2:00remaining
Identify the error in arithmetic expression
What error does this R code produce?
R Programming
x <- 10 y <- 0 z <- x / y print(z)
Attempts:
2 left
💡 Hint
Check how R handles division by zero with numeric values.
✗ Incorrect
In R, dividing a positive number by zero returns Inf (infinity), not an error.
❓ Predict Output
advanced2:00remaining
Output of combined arithmetic and logical operators
What is the output of this R code?
R Programming
a <- 4 b <- 2 result <- (a > b) + (b == 2) * 3 print(result)
Attempts:
2 left
💡 Hint
Logical TRUE is 1 and FALSE is 0 in arithmetic operations.
✗ Incorrect
a > b is TRUE (1), b == 2 is TRUE (1), so result = 1 + 1*3 = 4.
🧠 Conceptual
expert2:00remaining
Number of elements in a vector after arithmetic recycling
Given the code below, how many elements does the resulting vector have?
R Programming
v1 <- c(1, 2, 3, 4, 5) v2 <- c(10, 20) result <- v1 + v2
Attempts:
2 left
💡 Hint
R recycles shorter vectors to match the length of longer vectors.
✗ Incorrect
v2 is recycled to length 5: (10,20,10,20,10), so result length is 5.