Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a hash with a symbol key :name and value "Alice".
Ruby
person = { [1] => "Alice" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "name" instead of a symbol :name.
Using a bare word name without quotes or colon.
✗ Incorrect
The symbol :name is used as a key in the hash.
2fill in blank
mediumComplete the code to create a hash with a string key "age" and value 30.
Ruby
person = { [1] => 30 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a symbol :age instead of a string "age".
Using a bare word age without quotes or colon.
✗ Incorrect
The string "age" is used as a key in the hash.
3fill in blank
hardFix the error in the hash creation by completing the code with the correct symbol key.
Ruby
person = { [1]: "Bob" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using :name: which is invalid syntax.
Using "name": which is a string key, not symbol shorthand.
✗ Incorrect
When using the symbol key shorthand, the key is written without the colon prefix, just the name.
4fill in blank
hardFill both blanks to create a hash with symbol key :city and string key "country".
Ruby
location = { [1] => "Paris", [2] => "France" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up symbol and string keys.
Using bare words without colon or quotes.
✗ Incorrect
The first key is a symbol :city, the second key is a string "country".
5fill in blank
hardFill all three blanks to create a hash with symbol keys :name and :age, and string key "city".
Ruby
person = { [1] => "Eve", [2] => 28, [3] => "Berlin" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "age" instead of symbol :age.
Mixing up quotes and colons for keys.
✗ Incorrect
The keys are symbol :name, symbol :age, and string "city".