0
0
Rubyprogramming~10 mins

How Ruby interprets code at runtime - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print 'Hello, Ruby!' to the console.

Ruby
puts [1]
Drag options to blanks, or click blank then click option'
A'Hello Ruby'
BHello, Ruby!
C"Hello, Ruby!"
Dprint 'Hello, Ruby!'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Using print instead of puts when the instruction asks for puts.
2fill in blank
medium

Complete 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'
Auser
Bname
Cgreet
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the method parameter.
Forgetting that Ruby variables are case-sensitive.
3fill in blank
hard

Fix 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to put spaces around operators (though Ruby allows it).
4fill in blank
hard

Fill 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'
Aname
Bage
Cjob
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings as keys instead of symbols.
Choosing keys that don't match the values.
5fill in blank
hard

Fill 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'
A2
B4
C6
Deven
Attempts:
3 left
💡 Hint
Common Mistakes
Using odd numbers in the array.
Forgetting to use the even? method to filter.