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 = "100"
value = value + 50
puts value
ASyntaxError: invalid assignment
BNo error, outputs "150"
CTypeError: Integer can't be added to String
DOutputs "10050"
Step-by-Step Solution
Solution:
  1. Step 1: Check operation types

    value is a String "100", then tries to add Integer 50.
  2. Step 2: Ruby type rules

    Ruby does not auto-convert String and Integer in addition, causing a TypeError.
  3. Final Answer:

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

    Cannot add String and Integer directly [OK]
Quick Trick: Convert types before adding different kinds [OK]
Common Mistakes:
  • Expecting automatic conversion to number
  • Thinking output is concatenated string
  • Confusing syntax error with type error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes