Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to change the string content.
Ruby
str = "hello" str[1] " world" puts str
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which creates a new string instead of modifying.
✗ Incorrect
In Ruby, the << operator appends to the original string, showing mutability.
2fill in blank
mediumComplete the code to replace part of the string.
Ruby
str = "hello" str[1] 0, 5, "hi" puts str
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sub which returns a new string without modifying original.
✗ Incorrect
The []= method replaces part of the string in place, showing mutability.
3fill in blank
hardFix the error in the code to mutate the string.
Ruby
str = "hello" str.[1](" world") puts str
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sub or gsub which return new strings without mutating.
✗ Incorrect
The concat method appends to the string in place, mutating it.
4fill in blank
hardFill both blanks to create a mutable string and modify it.
Ruby
str = [1]"hello" str[2] " world" puts str
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which creates a new string instead of modifying.
✗ Incorrect
Using String.new creates a mutable string object, and << appends to it.
5fill in blank
hardFill all three blanks to replace part of the string and show mutability.
Ruby
str = "hello" str[1] 0, 5, [2] puts str puts str[3] "!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which creates new strings instead of mutating.
✗ Incorrect
The []= method replaces part of the string, and << appends to it, both mutating the string.