Bird
0
0

You want to check if a variable status is either true or nil in Ruby. Which condition correctly does this?

hard📝 Application Q15 of 15
Ruby - Variables and Data Types
You want to check if a variable status is either true or nil in Ruby. Which condition correctly does this?
Aif status == true || status == nil
Bif status == true && status == nil
Cif status || nil
Dif status != false
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition requirements

    You want to check if status is either true OR nil, so use logical OR (||).
  2. Step 2: Analyze each option

    if status == true || status == nil uses status == true || status == nil, which matches the requirement. if status == true && status == nil uses AND, which can never be true for both at once. if status || nil is incorrect syntax and logic. if status != false checks if status is not false, which includes other values too.
  3. Final Answer:

    if status == true || status == nil -> Option A
  4. Quick Check:

    Use OR (||) to check either condition [OK]
Quick Trick: Use || to check if either condition is true [OK]
Common Mistakes:
  • Using && instead of ||
  • Confusing != false with true or nil
  • Writing invalid condition syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes