Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a string object in Ruby.
Ruby
greeting = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text.
Using a method that does not exist like string().
✗ Incorrect
In Ruby, strings are objects created by enclosing text in quotes.
2fill in blank
mediumComplete the code to check the class of an object in Ruby.
Ruby
number = 10 puts number.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
type which is not a Ruby method.Using
kind or object_type which do not exist.✗ Incorrect
The class method returns the class of an object in Ruby.
3fill in blank
hardFix the error in the code to call a method on an integer object.
Ruby
num = 5 puts num.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use string methods on numbers.
Using methods that do not exist for integers.
✗ Incorrect
Integers do not have a length, upcase, or split method. to_s converts the integer to a string.
4fill in blank
hardFill both blanks to create a hash with symbol keys and access a value.
Ruby
person = { [1]: "Alice", [2]: 30 }
age = person[:age]
puts age Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings as keys but accessing with symbols.
Putting quotes around keys when symbols are expected.
✗ Incorrect
Symbols like :name and :age are used as keys in Ruby hashes. Accessing with person[:age] returns 30.
5fill in blank
hardFill all three blanks to create an array, add an element, and print its length.
Ruby
fruits = [1] fruits.[2]("banana") puts fruits.[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
append which is not a Ruby array method.Using parentheses instead of square brackets for arrays.
✗ Incorrect
An empty array is []. Use push to add an element. length returns the number of elements.