Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Variables and Data Types
Identify the error in this Ruby code snippet:
value = "hello"
if value.class = String
  puts "It's a string"
end
AUsing .class instead of .is_a?
BMissing parentheses in if condition
CUsing single = instead of == for comparison
DUsing puts instead of print
Step-by-Step Solution
Solution:
  1. Step 1: Check the if condition syntax

    The condition uses single = which is assignment, not comparison.
  2. Step 2: Correct the comparison operator

    It should be == to compare value.class with String.
  3. Final Answer:

    Using single = instead of == for comparison -> Option C
  4. Quick Check:

    Use == for comparison, not = [OK]
Quick Trick: Use == for comparison, not = [OK]
Common Mistakes:
  • Using = instead of ==
  • Confusing .class with .is_a?
  • Ignoring syntax errors in if condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes