Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a method named greet.
Ruby
def [1] puts "Hello!" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than 'greet'.
Forgetting to write the method name after 'def'.
✗ Incorrect
The method name should be greet as specified.
2fill in blank
mediumComplete the code to declare a method named add that takes two parameters.
Ruby
def [1](a, b) a + b end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than 'add'.
Leaving out the parameters.
✗ Incorrect
The method name should be add as specified.
3fill in blank
hardFix the error in the method declaration by completing the method name.
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.
Choosing a method name that does not match the greeting.
✗ Incorrect
The method name should be greet to match the usage.
4fill in blank
hardFill both blanks to declare a method that returns the square of a number.
Ruby
def [1](num) num [2] 2 end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication (*) instead of exponentiation (**).
Choosing a method name that does not describe squaring.
✗ Incorrect
The method name is square and the exponent operator is ** in Ruby.
5fill in blank
hardFill all three blanks to declare a method that greets a person with their name and age.
Ruby
def [1](name, age) puts "Hello, [2]! You are [3] years old." end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use string interpolation syntax.
Using a method name that is too generic.
✗ Incorrect
The method name is greet_person. Use Ruby string interpolation #{name} and #{age} to insert values.