0
0
Rubyprogramming~10 mins

Logical 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 both conditions are true using the AND operator.

Ruby
if a [1] b
  puts "Both are true"
end
Drag options to blanks, or click blank then click option'
A||
B&&
C!
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using || which means OR instead of AND.
Using ! which means NOT and changes the meaning.
2fill in blank
medium

Complete the code to check if either condition is true using the OR operator.

Ruby
if x [1] y
  puts "At least one is true"
end
Drag options to blanks, or click blank then click option'
A&&
B==
C!
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which means AND instead of OR.
Using == which checks equality, not logical OR.
3fill in blank
hard

Fix the error in the code by completing the NOT operator usage.

Ruby
if [1] is_valid
  puts "Invalid input"
end
Drag options to blanks, or click blank then click option'
A!
B||
C&&
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using && or || which are AND/OR, not NOT.
Using == which checks equality, not negation.
4fill in blank
hard

Fill both blanks to create a condition that checks if a is true AND b is false.

Ruby
if a [1] [2]b
  puts "Condition met"
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 AND.
Not negating b when needed.
5fill in blank
hard

Fill all three blanks to create a condition that checks if x is true OR y is false AND z is true.

Ruby
if x [1] [2]y [3] z
  puts "Complex condition met"
end
Drag options to blanks, or click blank then click option'
A&&
B!
C||
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up AND and OR operators.
Forgetting to negate y.