Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a greeting message using a conventional Ruby method.
Ruby
def greet puts [1] end greet
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print without quotes
Using JavaScript syntax like console.log
✗ Incorrect
In Ruby, puts prints a string with a newline. The string must be in quotes.
2fill in blank
mediumComplete the code to define a class with a conventional Ruby naming style.
Ruby
class [1] def initialize(name) @name = name end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or snake_case for class names
✗ Incorrect
Ruby classes use CamelCase starting with a capital letter by convention.
3fill in blank
hardFix the error in the method name to follow Ruby conventions.
Ruby
def [1](age) puts "Age is #{age}" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CamelCase or uppercase for method names
✗ Incorrect
Ruby method names use snake_case with lowercase letters and underscores.
4fill in blank
hardFill both blanks to create a hash with symbol keys using Ruby conventions.
Ruby
person = { [1]: "Alice", [2]: 30 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings or bare words as keys without colon
✗ Incorrect
Ruby uses symbols (starting with :) as keys in hashes by convention.
5fill in blank
hardFill all three blanks to write a conventional Ruby loop that prints numbers 1 to 3.
Ruby
3.times do |[1]| puts [2] + [3] end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not adding 1 to start counting at 1
✗ Incorrect
The block variable i counts from 0, so adding 1 prints numbers 1 to 3.