Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a method that checks if a number is even using the correct naming convention.
Ruby
def even[1](number) number % 2 == 0 end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' for a method that returns a boolean.
Adding arbitrary suffixes like '_check' or '_test' which are not Ruby conventions.
✗ Incorrect
In Ruby, methods that return a boolean value often end with a question mark (?).
2fill in blank
mediumComplete the code to define a method that modifies a string in place, following Ruby naming conventions.
Ruby
def capitalize[1](str) str.capitalize! end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?' instead of '!' for methods that modify objects.
Adding suffixes like '_inplace' which are not standard Ruby conventions.
✗ Incorrect
In Ruby, methods that modify the object they are called on usually end with an exclamation mark (!).
3fill in blank
hardFix the error in the method name to follow Ruby conventions for a method that returns a boolean.
Ruby
def valid_email[1](email) email.include?('@') end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' for boolean methods.
Using arbitrary suffixes like '_check' or '_valid'.
✗ Incorrect
Boolean methods in Ruby should end with a question mark (?).
4fill in blank
hardComplete the code to define a method that modifies an array in place and returns a boolean indicating success.
Ruby
def add_element[1](array, element) array << element true end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '?' after the parameter list which is invalid syntax.
Not using '!' for methods that modify objects.
✗ Incorrect
Methods that modify objects end with '!' and the '?' is not used here because the method returns true explicitly.
5fill in blank
hardFill both blanks to define a method that checks if a string is empty and modifies it if not, following Ruby conventions.
Ruby
def process_string[1](str) if str.empty[2] false else str.upcase! true end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' for boolean methods.
Adding suffixes after the parameter list which is invalid.
✗ Incorrect
The method name ends with '?', no suffix after parameters, and 'empty?' is a Ruby method that ends with '?'.