Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a method named greet.
Ruby
def [1](name) puts "Hello, #{name}!" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase instead of snake_case for method names.
Using a method name different from 'greet'.
✗ Incorrect
The method name should be greet as specified.
2fill in blank
mediumComplete the code to create a symbol for the key :age.
Ruby
person = { [1] => 30 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of symbols for hash keys.
Omitting the colon before the symbol name.
✗ Incorrect
Symbols in Ruby start with a colon, like :age.
3fill in blank
hardFix the error in the code by completing the conditional statement.
Ruby
if number [1] 10 puts "Number is less than 10" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment operator
=> instead of comparison.Using equality operator
== which checks for equality, not less than.✗ Incorrect
The less than operator is < to compare if number is smaller than 10.
4fill in blank
hardFill both blanks to create a loop that prints numbers 1 to 5.
Ruby
(1[1]5).each do |i| puts i [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
until instead of a range.Forgetting to close the block with
end.✗ Incorrect
The range operator .. creates numbers from 1 to 5, and end closes the block.
5fill in blank
hardFill all three blanks to create a hash with keys as symbols and values as strings.
Ruby
person = { [1]: [2], [3]: "Developer" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around keys.
Not quoting string values.
✗ Incorrect
Keys are symbols without quotes, values are strings with quotes.