Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign nil to the variable.
Ruby
value = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' or 'None' which are from other languages.
Using 'undefined' which is not a Ruby keyword.
✗ Incorrect
In Ruby, nil represents the absence of a value.
2fill in blank
mediumComplete the code to check if the variable is nil.
Ruby
if value.[1]? puts "Value is nil" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'empty?' which checks if a collection has no elements.
Using 'null?' or 'none?' which do not exist in Ruby.
✗ Incorrect
The method nil? returns true if the object is nil.
3fill in blank
hardFix the error in the code to assign nil correctly.
Ruby
result = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized versions like 'Nil' or 'Null'.
Using uppercase 'NULL' which is not Ruby syntax.
✗ Incorrect
Ruby is case-sensitive. The correct keyword is lowercase nil.
4fill in blank
hardFill both blanks to create a hash with keys and nil values for missing data.
Ruby
person = { name: "Alice", age: [1], city: [2] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings like 'unknown' or 'none' instead of nil.
Mixing string and nil values inconsistently.
✗ Incorrect
Use nil to represent missing or unknown values in Ruby hashes.
5fill in blank
hardFill all three blanks to return a default value if the variable is nil.
Ruby
default = "Guest" name = [1] || [2] if [3].nil?
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not checking for nil properly.
✗ Incorrect
This code assigns default if input_name is nil.