0
0
Rubyprogramming~10 mins

Prepend for method chain insertion in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to prepend a string to another string.

Ruby
result = 'world'.[1]('Hello ')
puts result
Drag options to blanks, or click blank then click option'
Aprepend
Bappend
Cinsert
Dconcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which adds text at the end.
Using 'concat' which also adds at the end.
2fill in blank
medium

Complete the code to prepend 'Mr. ' to the name variable.

Ruby
name = 'Smith'
name.[1]('Mr. ')
puts name
Drag options to blanks, or click blank then click option'
Aconcat
Bprepend
Cinsert
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which adds text at the end.
Using 'insert' with wrong index.
3fill in blank
hard

Fix the error in the code to prepend 'Hello, ' to the greeting string.

Ruby
greeting = 'world'
greeting.[1]('Hello, ')
puts greeting
Drag options to blanks, or click blank then click option'
Aappend
Bconcat
Cprepend
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which adds text at the end.
Using 'concat' which adds at the end.
4fill in blank
hard

Fill both blanks to prepend 'Hello, ' and then append '!' to the string.

Ruby
text = 'world'
text.[1]('Hello, ').[2]('!')
puts text
Drag options to blanks, or click blank then click option'
Aprepend
Bappend
Cconcat
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' first which adds at the end before prepending.
Using 'concat' instead of 'append'.
5fill in blank
hard

Fill all three blanks to prepend 'Hello, ', convert to uppercase, and then append '!' to the string.

Ruby
text = 'world'
text = text.[1]('Hello, ').[2].[3]('!')
puts text
Drag options to blanks, or click blank then click option'
Aprepend
Bupcase
Cappend
Ddowncase
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'downcase' instead of 'upcase'.
Appending before prepending.