0
0
Rubyprogramming~10 mins

Why dynamic typing matters in Ruby - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assign a string to the variable.

Ruby
name = [1]
Drag options to blanks, or click blank then click option'
A42
B:symbol
C"Alice"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string.
Using a symbol when a string is expected.
2fill in blank
medium

Complete the code to add a number to the variable without declaring its type.

Ruby
age = [1]
Drag options to blanks, or click blank then click option'
A30
B:thirty
Cfalse
D"twenty"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes, making it a string.
Using a symbol instead of a number.
3fill in blank
hard

Fix the error by completing the code to concatenate a string and a number using dynamic typing.

Ruby
result = "Age: " + [1].to_s
Drag options to blanks, or click blank then click option'
Aage
B"age"
C:age
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using the string "age" instead of the variable.
Using a symbol instead of the variable.
4fill in blank
hard

Fill both blanks to create a hash with dynamic keys and values.

Ruby
person = { [1] => [2] }
Drag options to blanks, or click blank then click option'
A:name
B"Alice"
Cage
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string as a key instead of a symbol.
Using a number as a key or value incorrectly.
5fill in blank
hard

Fill all three blanks to create a hash with mixed key types and values.

Ruby
data = { [1] => [2], [3] => 100 }
Drag options to blanks, or click blank then click option'
A:score
B42
C"level"
D:points
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of symbols for keys.
Mixing up keys and values.