0
0
Rubyprogramming~10 mins

Why Ruby emphasizes developer happiness - Test Your Understanding

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

Complete the code to print a friendly greeting in Ruby.

Ruby
puts [1]
Drag options to blanks, or click blank then click option'
A"Hello, friend!"
Bprint("Hello, friend!")
Cecho "Hello, friend!"
Dconsole.log("Hello, friend!")
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of puts without quotes
Using JavaScript or shell commands instead of Ruby syntax
2fill in blank
medium

Complete the code to define a method that returns a happy message.

Ruby
def happy_message
  [1]
end
Drag options to blanks, or click blank then click option'
Areturn "Keep smiling!"
B"Keep smiling!"
Cputs "Keep smiling!"
Dprint "Keep smiling!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using puts or print which outputs but returns nil
Using return unnecessarily
3fill in blank
hard

Fix the error in the code to create a symbol representing happiness.

Ruby
mood = [1]
Drag options to blanks, or click blank then click option'
A":happy"
Bhappy
C:happy
D'happy'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the symbol
Using a plain word without colon
4fill in blank
hard

Fill both blanks to create a hash with a symbol key and a string value.

Ruby
feelings = { [1] => [2] }
Drag options to blanks, or click blank then click option'
A:joy
B"happy"
C:happy
D"joy"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for keys instead of symbols
Mixing up keys and values
5fill in blank
hard

Fill all three blanks to create a method that returns a hash with a symbol key and string value.

Ruby
def [1]
  { [2] => [3] }
end
Drag options to blanks, or click blank then click option'
Ahappy_hash
B:smile
C"Keep happy!"
Dsmile
Attempts:
3 left
💡 Hint
Common Mistakes
Using a symbol as method name
Not quoting the string value
Using string as key instead of symbol