Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to freeze the string so it cannot be changed.
Ruby
name = "Ruby".[1] name << "Lang"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string methods that modify content instead of freezing.
Not calling any method and expecting immutability.
✗ Incorrect
Using freeze makes the string immutable, so appending to it causes an error.
2fill in blank
mediumComplete the code to freeze the array so it cannot be modified.
Ruby
numbers = [1, 2, 3].[1] numbers << 4
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sorting or reversing methods instead of freezing.
Trying to modify without freezing first.
✗ Incorrect
Calling freeze on the array prevents adding new elements.
3fill in blank
hardFix the error by freezing the hash so it cannot be changed.
Ruby
config = {mode: 'dark', volume: 10}
config.[1]
config[:mode] = 'light' Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that remove or copy instead of freezing.
Not freezing before trying to modify.
✗ Incorrect
Freezing the hash prevents changing its keys or values.
4fill in blank
hardFill both blanks to create a frozen array and check if it is frozen.
Ruby
arr = [10, 20, 30].[1] puts arr.[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
empty? or length instead of frozen?.Not freezing the array before checking.
✗ Incorrect
First, freeze the array to make it immutable, then check with frozen?.
5fill in blank
hardFill all three blanks to freeze a nested hash and check if the nested array is frozen.
Ruby
settings = {theme: 'blue', options: [1, 2, 3]}
settings = settings.[1]
puts settings[:options].[2]
settings[:options].[3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming freezing outer hash freezes nested objects.
Not freezing nested array separately.
✗ Incorrect
Freeze the outer hash, check if the nested array is frozen (it is not), then freeze the nested array separately to make it immutable.