Challenge - 5 Problems
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this R code involving arithmetic and logical operators?
Consider the following R code snippet. What will be printed when it runs?
R Programming
result <- 3 + 4 * 2 > 10 print(result)
Attempts:
2 left
💡 Hint
Remember that multiplication happens before addition, and comparison operators are evaluated last.
✗ Incorrect
Multiplication (*) has higher precedence than addition (+), so 4 * 2 = 8. Then 3 + 8 = 11. Comparisons have lower precedence than arithmetic operators, so finally 11 > 10 is TRUE. Output: [1] TRUE.
❓ Predict Output
intermediate2:00remaining
What is the value of x after this R expression?
What is the value of x after running this code?
R Programming
x <- 5 x <- x ^ 2 %% 3 print(x)
Attempts:
2 left
💡 Hint
Remember that exponentiation (^) has higher precedence than modulo (%%).
✗ Incorrect
First, x ^ 2 is 5 squared = 25. Then 25 %% 3 is the remainder of 25 divided by 3, which is 1.
❓ Predict Output
advanced2:00remaining
What does this R code print with mixed logical and arithmetic operators?
What is the output of this R code?
R Programming
a <- 2 b <- 3 result <- a + b > 4 & b < 5 print(result)
Attempts:
2 left
💡 Hint
Check operator precedence: arithmetic first, then comparison, then logical AND (&).
✗ Incorrect
First, a + b = 5. Then 5 > 4 is TRUE. Also, b < 5 is TRUE. TRUE & TRUE is TRUE.
❓ Predict Output
advanced2:00remaining
What is the output of this R code with nested parentheses and operators?
What will this code print?
R Programming
x <- 4 result <- (x + 2) * (x - 1) / 2 print(result)
Attempts:
2 left
💡 Hint
Calculate inside parentheses first, then multiplication and division from left to right.
✗ Incorrect
(4 + 2) = 6, (4 - 1) = 3, then 6 * 3 / 2. Since * and / have the same precedence and are left-associative, (6 * 3) / 2 = 18 / 2 = 9.
❓ Predict Output
expert3:00remaining
What is the output of this complex R expression with mixed operators?
What does this R code print?
R Programming
x <- 3 y <- 4 z <- 5 result <- x + y * z ^ 2 %% 7 - 1 print(result)
Attempts:
2 left
💡 Hint
Remember the order: exponentiation (^), modulo (%%), multiplication (*), addition (+), subtraction (-).
✗ Incorrect
Precedence: ^ first (right-associative), so z ^ 2 = 25.
Then * and %% have the same precedence (left-associative), so (y * 25) %% 7 = 100 %% 7 = 2 (since 7*14=98, 100-98=2).
Then + and - (left-associative): x + 2 = 5, 5 - 1 = 4.