Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the class of the number 10.
Ruby
puts 10.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'type' instead of 'class' causes an error.
✗ Incorrect
In Ruby, class is the method to get the class of an object.
2fill in blank
mediumComplete the code to call the upcase method on the string 'hello'.
Ruby
puts 'hello'.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'capitalize' only changes the first letter.
✗ Incorrect
The upcase method converts all letters in a string to uppercase.
3fill in blank
hardFix the error in the code to check if 5 is an object.
Ruby
puts 5.[1](Object)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'object?' or 'is_object?' are not valid Ruby methods.
✗ Incorrect
The is_a? method checks if an object is an instance of a class or its subclass.
4fill in blank
hardFill both blanks to create a hash where keys are strings and values are their lengths.
Ruby
lengths = ['cat', 'dog', 'bird'].each_with_object({}) { |word, h| h[[1]] = [2] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
word.size also works but is not the expected answer here.✗ Incorrect
The key is the word itself, and the value is its length using length.
5fill in blank
hardFill all three blanks to create a hash with uppercase keys and values greater than 3.
Ruby
result = ['apple', 'bat', 'cat', 'dog'].each_with_object({}) { |word, h| if [3]; h[[1]] = [2] end }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
word.size < 3 filters the wrong words.✗ Incorrect
Keys are uppercase words, values are the original words, filtered by length greater than 3.