Bird
0
0

Identify the error in the following Ruby code:

medium📝 Debug Q14 of 15
Ruby - Variables and Data Types
Identify the error in the following Ruby code:
str = 'It's a sunny day'
ASyntaxError due to missing double quotes
BNo error, string is valid
CSyntaxError due to unescaped single quote inside single-quoted string
DRuntime error due to invalid string
Step-by-Step Solution
Solution:
  1. Step 1: Check string delimiters and content

    The string uses single quotes outside and contains an unescaped single quote inside (It's), which breaks syntax.
  2. Step 2: Understand how to fix the error

    To fix, either escape the inner single quote as \' or use double quotes outside.
  3. Final Answer:

    SyntaxError due to unescaped single quote inside single-quoted string -> Option C
  4. Quick Check:

    Escape inner quotes or use double quotes [OK]
Quick Trick: Escape inner quotes or use double quotes [OK]
Common Mistakes:
  • Ignoring the need to escape inner single quotes
  • Assuming single quotes allow unescaped inner single quotes
  • Confusing syntax and runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes