0
0
Rubyprogramming~10 mins

Comparison 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 check if a is equal to b.

Ruby
if a [1] b
  puts "Equal"
end
Drag options to blanks, or click blank then click option'
A==
B=
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
2fill in blank
medium

Complete the code to check if x is greater than 10.

Ruby
if x [1] 10
  puts "x is big"
end
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for checking greater than.
3fill in blank
hard

Fix the error in the code to check if num is not equal to 5.

Ruby
if num [1] 5
  puts "Not five"
end
Drag options to blanks, or click blank then click option'
A==
B=
C<>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '!=' for not equal comparison.
4fill in blank
hard

Fill both blanks to check if age is between 18 and 65 inclusive.

Ruby
if age [1] 18 && age [2] 65
  puts "Adult"
end
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' or '>' instead of '>='.
5fill in blank
hard

Fill all three blanks to create a hash with keys as uppercase words and values as word lengths greater than 3.

Ruby
result = words.select { |word| word.length [3] 3 }.map { |word| [ [1], [2] ] }.to_h
Drag options to blanks, or click blank then click option'
Aword.upcase
Bword.length
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'word.upcase' for keys.
Using '<' instead of '>' for length comparison.