0
0
Rubyprogramming~10 mins

Arithmetic operators in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add two numbers and print the result.

Ruby
result = 5 [1] 3
puts result
Drag options to blanks, or click blank then click option'
A*
B-
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' subtracts instead of adding.
Using '*' multiplies instead of adding.
2fill in blank
medium

Complete the code to multiply two numbers and print the result.

Ruby
result = 4 [1] 7
puts result
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds instead of multiplying.
Using '/' divides instead of multiplying.
3fill in blank
hard

Fix the error in the code to correctly divide two numbers and print the result.

Ruby
result = 10 [1] 2
puts result
Drag options to blanks, or click blank then click option'
A/
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' multiplies instead of dividing.
Using '-' subtracts instead of dividing.
4fill in blank
hard

Fill both blanks to calculate the remainder of division and print it.

Ruby
result = 17 [1] 5
puts result.to_s [2] " remainder"
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '%' for remainder.
Using '-' or '*' instead of '+' for concatenation.
5fill in blank
hard

Fill all three blanks to create a hash with keys as numbers and values as their squares, but only for numbers greater than 3.

Ruby
squares = (1..5).select { |[3]| [3] > 3 }.map { |[3]| [ [1], [2] ] }.to_h
Drag options to blanks, or click blank then click option'
Ax
Bx * x
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using incorrect operators for multiplication.