0
0
Rubyprogramming~10 mins

Dynamic typing vs strong typing in Ruby - Interactive Practice

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'
A"Alice"
B42
Ctrue
D:symbol
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number or boolean instead of a string.
2fill in blank
medium

Complete the code to add two numbers.

Ruby
sum = 10 [1] 5
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
3fill in blank
hard

Fix the error in the code by choosing the correct method to convert a number to a string.

Ruby
number = 100
text = number.[1]
Drag options to blanks, or click blank then click option'
Ato_sym
Bto_i
Cto_s
Dto_a
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_i which converts to integer, not string.
4fill in blank
hard

Fill both blanks to create a hash with keys as symbols and values as strings.

Ruby
person = { [1]: [2] }
Drag options to blanks, or click blank then click option'
A:name
B"Bob"
Cname
DBob
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string as a key without colon or unquoted value.
5fill in blank
hard

Fill all three blanks to create a method that takes a parameter and returns its class name as a string.

Ruby
def get_type([1])
  [2].class.[3]
end
Drag options to blanks, or click blank then click option'
Avalue
Cto_s
Dclass_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name or method that doesn't convert to string.