Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign a string to the variable.
Ruby
name = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number or boolean instead of a string.
✗ Incorrect
In Ruby, strings are written inside double quotes. Here, "Alice" is a string.
2fill in blank
mediumComplete the code to add two numbers.
Ruby
sum = 10 [1] 5
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
✗ Incorrect
The plus sign (+) adds two numbers together in Ruby.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_i which converts to integer, not string.
✗ Incorrect
In Ruby, to_s converts a number to a string.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string as a key without colon or unquoted value.
✗ Incorrect
In Ruby, hash keys can be symbols like :name, and values can be strings like "Bob".
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name or method that doesn't convert to string.
✗ Incorrect
The method takes a parameter named value. Then it calls value.class.to_s to get the class name as a string.