Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Variables and Data Types
Identify the error in this Ruby code snippet:
number = 5
number = number + "3"
puts number
ATypeError: cannot add Integer and String
BNo error, output is 8
CSyntaxError: invalid syntax
DOutput is '53'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the operation number + "3"

    Adding an integer (5) and a string ("3") is not allowed in Ruby.
  2. Step 2: Identify the error type

    This causes a TypeError because Ruby cannot combine different types with +.
  3. Final Answer:

    TypeError: cannot add Integer and String -> Option A
  4. Quick Check:

    Adding different types causes TypeError [OK]
Quick Trick: Cannot add number and string directly in Ruby [OK]
Common Mistakes:
  • Assuming Ruby auto-converts types
  • Expecting output '53' without conversion
  • Ignoring error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes