String Methods Interactive Practice
What will each of the following lines of code return?
???
String Practice
?: puts "i am super excited about coding!".upcase
( ) "I Am Super Excited About Coding!" (X) "I AM SUPER EXCITED ABOUT CODING!" ( ) "I aM sUPER eXCITED aBOUT cODING!"
?: puts "stressed".reverse
( ) "STRESSED" ( ) "sTrEsSeD" (X) "desserts"
?: puts "Hi! My name is Joe".swapcase
(X) "hI! mY NAME IS jOE" ( ) "HI! MY NAME IS JOE" ( ) "hi! my name is joe"
?: puts "short string".length
(X) 12 ( ) 11 ( ) 2
?: puts "backwards".reverse.upcase
( ) "sdrawkcab" ( ) "BACKWARDS" (X) "SDRAWKCAB"
???
???
Now it's your turn to use string methods.
?: Get enthusiastic about ruby! How do I print out "I love ruby" in all caps?
( ) '"I love Ruby".swapcase' (X) '"I love Ruby".upcase' ( ) '"I love Ruby".uppercase'
?: Use a method to print out how long this sentence is: "This is a pretty long string. I wonder how long it is?"
(X) '"This is a pretty long string. I wonder how long it is?".length' ( ) '"This is a pretty long string. I wonder how long it is?".swapcase' ( ) '"This is a pretty long string. I wonder how long it is?".printlength'
?: It's backwards day! How would you print "backwards" backwards?
( ) '"backwards".length' ( ) '"backwards".backwards' (X) '"backwards".reverse'
?: Wouldn't it be great if there was a string method that always capitalized the first letter of a string? There is! "make it capitalize the first letter in this string!"
( ) '"make it capitalize the first letter in this string!".upcase' ( ) '"make it capitalize the first letter in this string!".swapcase' (X) '"make it capitalize the first letter in this string!".capitalize'
?: How much do we love "Ruby"? So much that we want to say it in all caps AND backwards. How would you do this?
( ) '"Ruby".captialize.reverse' ( ) '"Ruby".reverse.swapcase' (X) '"Ruby".upcase.reverse'
???
View String Methods Interactive Practice on Learn.co and start learning to code for free.