Challenge - 5 Problems
String Methods Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Ruby code?
Consider the following Ruby code snippet. What will it print?
Ruby
str = " Hello World " puts str.strip.upcase
Attempts:
2 left
💡 Hint
Remember that
strip removes spaces at the start and end, and upcase makes all letters uppercase.✗ Incorrect
The
strip method removes spaces at the beginning and end of the string, so " Hello World " becomes "Hello World". Then upcase converts all letters to uppercase, resulting in "HELLO WORLD".❓ Predict Output
intermediate2:00remaining
What does this Ruby code print?
Look at this code. What is the output?
Ruby
text = " Ruby Programming " puts text.downcase.strip
Attempts:
2 left
💡 Hint
Think about what
downcase and strip do to the string.✗ Incorrect
First,
downcase converts all letters to lowercase, so " Ruby Programming " becomes " ruby programming ". Then strip removes the spaces at the start and end, leaving "ruby programming".🔧 Debug
advanced2:00remaining
Why does this code raise an error?
This Ruby code tries to print a string in uppercase after stripping spaces, but it raises an error. What is the cause?
Ruby
str = nil puts str.strip.upcase
Attempts:
2 left
💡 Hint
Think about what happens if you call a method on
nil in Ruby.✗ Incorrect
The variable
str is nil, which means it has no value. Calling strip on nil causes a NoMethodError because nil does not have the strip method.🧠 Conceptual
advanced2:00remaining
What is the result of chaining these methods?
Given the string
" Ruby Rocks! ", what does str.downcase.strip.upcase return?Ruby
str = " Ruby Rocks! " result = str.downcase.strip.upcase puts result
Attempts:
2 left
💡 Hint
Remember the order:
downcase then strip then upcase.✗ Incorrect
First,
downcase converts all letters to lowercase: " ruby rocks! ". Then strip removes spaces at start and end: "ruby rocks!". Finally, upcase converts all letters to uppercase: "RUBY ROCKS!".📝 Syntax
expert2:00remaining
Which option causes a syntax error?
Which of these Ruby code snippets will cause a syntax error?
Attempts:
2 left
💡 Hint
Look for missing or extra characters in method calls.
✗ Incorrect
Option B has an opening parenthesis after
upcase but no closing parenthesis, causing a syntax error.