0
0
Rubyprogramming~10 mins

Hash creation with symbols and strings 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 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'
Aname:
B"name"
Cname
D:name
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "name" instead of a symbol :name.
Using a bare word name without quotes or colon.
2fill in blank
medium

Complete 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'
A:age
Bage
C"age"
Dage:
Attempts:
3 left
💡 Hint
Common Mistakes
Using a symbol :age instead of a string "age".
Using a bare word age without quotes or colon.
3fill in blank
hard

Fix 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'
Aname
B"name"
C:name
Dname:
Attempts:
3 left
💡 Hint
Common Mistakes
Using :name: which is invalid syntax.
Using "name": which is a string key, not symbol shorthand.
4fill in blank
hard

Fill 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'
A:city
B"city"
C"country"
D:country
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up symbol and string keys.
Using bare words without colon or quotes.
5fill in blank
hard

Fill 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'
A:name
B:age
C"city"
D"age"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "age" instead of symbol :age.
Mixing up quotes and colons for keys.