Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print 'Hello, Ruby!' to the console.
Ruby
puts [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Using print instead of puts when the instruction asks for puts.
✗ Incorrect
The puts method prints the string to the console. The string must be in quotes.
2fill in blank
mediumComplete the code to define a method named 'greet' that takes a name and prints a greeting.
Ruby
def greet(name) puts "Hello, #{ [1] }!" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the method parameter.
Forgetting that Ruby variables are case-sensitive.
✗ Incorrect
The method parameter name is used inside the string to greet the person.
3fill in blank
hardFix the error in the code to correctly add two numbers and print the result.
Ruby
a = 5 b = 10 puts a [1] b
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to put spaces around operators (though Ruby allows it).
✗ Incorrect
The plus sign + adds two numbers together in Ruby.
4fill in blank
hardFill both blanks to create a hash with keys as symbols and values as strings.
Ruby
person = { [1]: "Alice", [2]: "Developer" } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings as keys instead of symbols.
Choosing keys that don't match the values.
✗ Incorrect
Symbols like :name and :job are used as keys in Ruby hashes.
5fill in blank
hardFill all three blanks to create an array of numbers, select only even numbers, and print them.
Ruby
numbers = [[1], [2], [3]] even_numbers = numbers.select { |n| n.even? } puts even_numbers
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using odd numbers in the array.
Forgetting to use the
even? method to filter.✗ Incorrect
The array contains numbers 2, 4, and 6. The select method filters even numbers using even?.