0
0
Rubyprogramming~10 mins

Ruby style guide essentials - Interactive Code Practice

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

Complete the code to define a method named greet.

Ruby
def [1](name)
  puts "Hello, #{name}!"
end
Drag options to blanks, or click blank then click option'
Ahello
Bsay_hello
Cgreet
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase instead of snake_case for method names.
Using a method name different from 'greet'.
2fill in blank
medium

Complete the code to create a symbol for the key :age.

Ruby
person = { [1] => 30 }
Drag options to blanks, or click blank then click option'
A'age'
B"age"
Cage
D:age
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of symbols for hash keys.
Omitting the colon before the symbol name.
3fill in blank
hard

Fix the error in the code by completing the conditional statement.

Ruby
if number [1] 10
  puts "Number is less than 10"
end
Drag options to blanks, or click blank then click option'
A=>
B<
C==
D=>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment operator => instead of comparison.
Using equality operator == which checks for equality, not less than.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers 1 to 5.

Ruby
(1[1]5).each do |i|
  puts i
[2]
Drag options to blanks, or click blank then click option'
A..
Bend
Cuntil
Dfor
Attempts:
3 left
💡 Hint
Common Mistakes
Using until instead of a range.
Forgetting to close the block with end.
5fill in blank
hard

Fill all three blanks to create a hash with keys as symbols and values as strings.

Ruby
person = { [1]: [2], [3]: "Developer" }
Drag options to blanks, or click blank then click option'
Aname
B"Alice"
Cage
D"30"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around keys.
Not quoting string values.