Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Variables and Data Types
Find the error in this Ruby code snippet:
value = 10
value = value + "5"
puts value
ANo error, outputs 15
BSyntaxError: invalid string concatenation
CTypeError: String can't be coerced into Integer
DOutputs "105"
Step-by-Step Solution
Solution:
  1. Step 1: Analyze addition operation

    Adding integer 10 and string "5" is invalid in Ruby without conversion.
  2. Step 2: Identify error type

    Ruby raises TypeError because it cannot coerce string to integer automatically.
  3. Final Answer:

    TypeError: String can't be coerced into Integer -> Option C
  4. Quick Check:

    Strong typing prevents implicit string-integer addition [OK]
Quick Trick: Cannot add integer and string without conversion [OK]
Common Mistakes:
MISTAKES
  • Expecting automatic type conversion
  • Thinking output will be concatenated string
  • Ignoring runtime type errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes