Challenge - 5 Problems
Ruby String Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of single vs double quoted strings
What is the output of this Ruby code snippet?
Ruby
puts 'Hello\nWorld' puts "Hello\nWorld"
Attempts:
2 left
💡 Hint
Remember how single and double quotes treat escape sequences differently in Ruby.
✗ Incorrect
Single quoted strings do not interpret escape sequences like \n, so it prints literally. Double quoted strings interpret \n as a newline.
❓ Predict Output
intermediate2:00remaining
String interpolation behavior
What will this Ruby code output?
Ruby
name = 'Alice' puts 'Hello, #{name}!' puts "Hello, #{name}!"
Attempts:
2 left
💡 Hint
Check how Ruby treats #{...} inside single vs double quotes.
✗ Incorrect
Single quoted strings do not perform interpolation, so #{name} prints literally. Double quoted strings interpolate variables.
🔧 Debug
advanced2:00remaining
Identify the syntax error in string creation
Which option will cause a syntax error when running this Ruby code?
Ruby
str = 'It's a sunny day'
Attempts:
2 left
💡 Hint
Look carefully at how single quotes inside single quoted strings are handled.
✗ Incorrect
Option D uses single quotes inside single quotes without escaping, causing a syntax error. Other options handle the apostrophe correctly.
🧠 Conceptual
advanced2:00remaining
Difference in escape sequence handling
Which statement best describes how Ruby treats escape sequences in single and double quoted strings?
Attempts:
2 left
💡 Hint
Think about which escape sequences work in single quoted strings.
✗ Incorrect
In Ruby, double quoted strings interpret most escape sequences. Single quoted strings only interpret \\ and \' as escapes.
❓ Predict Output
expert3:00remaining
Complex string with mixed quotes and interpolation
What is the output of this Ruby code?
Ruby
value = 10 str = 'Value is #{value}' str2 = "Value is #{value}" str3 = %q{Value is #{value}} str4 = %Q{Value is #{value}} puts str puts str2 puts str3 puts str4
Attempts:
2 left
💡 Hint
Remember how %q and %Q behave like single and double quotes respectively.
✗ Incorrect
%q behaves like single quotes (no interpolation), %Q like double quotes (interpolation). Single quotes no interpolation, double quotes interpolate.