Bird
0
0

The following Ruby code is intended to convert a string name to lowercase and remove spaces at the start and end. What is wrong?

medium📝 Debug Q14 of 15
Ruby - String Operations
The following Ruby code is intended to convert a string name to lowercase and remove spaces at the start and end. What is wrong?
name = "  RubyLang  "
name.downcase.strip
AThe method <code>strip</code> does not exist
BThe methods are called in the wrong order
CThe result is not saved or printed
DThe string should be converted to uppercase instead
Step-by-Step Solution
Solution:
  1. Step 1: Check method calls and order

    Both downcase and strip are valid methods and can be chained in any order.
  2. Step 2: Check if result is used

    The code calls methods but does not save or print the result, so the original string remains unchanged.
  3. Final Answer:

    The result is not saved or printed -> Option C
  4. Quick Check:

    Method calls without assignment or output do nothing visible [OK]
Quick Trick: Always save or print method results to see changes [OK]
Common Mistakes:
  • Thinking method order matters here
  • Assuming methods change string in place
  • Confusing strip with a non-existent method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes