Recall & Review
beginner
What does the
+ operator do in Ruby?The
+ operator adds two numbers together. For example, 2 + 3 equals 5.Click to reveal answer
beginner
How do you perform division in Ruby and what is the result type?
Use the
/ operator to divide numbers. If both numbers are integers, Ruby returns an integer (floor division). To get a float result, use at least one float number, e.g., 5.0 / 2 returns 2.5.Click to reveal answer
beginner
What is the difference between
* and ** in Ruby?* multiplies two numbers, while ** raises a number to the power of another. For example, 3 * 4 is 12, but 3 ** 4 is 81 (3 to the power of 4).Click to reveal answer
beginner
What does the
% operator do in Ruby?The
% operator gives the remainder of division between two numbers. For example, 7 % 3 equals 1 because 7 divided by 3 leaves a remainder of 1.Click to reveal answer
intermediate
How can you combine arithmetic operators in Ruby?
You can combine operators like
+, -, *, /, and % in expressions. Ruby follows standard math order: parentheses first, then exponentiation, multiplication/division/modulus, and finally addition/subtraction.Click to reveal answer
What is the result of
10 / 4 in Ruby if both are integers?✗ Incorrect
When dividing two integers, Ruby returns the integer part only (floor division), so 10 / 4 equals 2.
Which operator raises a number to a power in Ruby?
✗ Incorrect
The
** operator is used for exponentiation in Ruby.What does
15 % 4 return?✗ Incorrect
The modulus operator
% returns the remainder. 15 divided by 4 leaves remainder 3.Which operator has the highest precedence in Ruby arithmetic?
✗ Incorrect
Exponentiation
** has higher precedence than multiplication, division, addition, and subtraction.What is the result of
2 + 3 * 4 in Ruby?✗ Incorrect
Multiplication happens before addition, so 3 * 4 = 12, then 2 + 12 = 14.
Explain how Ruby handles division between two integers and how to get a decimal result.
Think about how dividing 5 by 2 behaves differently with integers and floats.
You got /3 concepts.
Describe the order of operations for arithmetic operators in Ruby.
Remember the math rule PEMDAS but adapted for Ruby operators.
You got /4 concepts.