Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a friendly greeting in Ruby.
Ruby
puts [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of puts without quotes
Using JavaScript or shell commands instead of Ruby syntax
✗ Incorrect
In Ruby, puts prints the string with a newline. The string must be in quotes.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using puts or print which outputs but returns nil
Using return unnecessarily
✗ Incorrect
In Ruby, the last expression is returned automatically, so just the string is enough.
3fill in blank
hardFix the error in the code to create a symbol representing happiness.
Ruby
mood = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the symbol
Using a plain word without colon
✗ Incorrect
In Ruby, symbols start with a colon and are not quoted.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for keys instead of symbols
Mixing up keys and values
✗ Incorrect
The key is a symbol :happy and the value is a string "happy".
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a symbol as method name
Not quoting the string value
Using string as key instead of symbol
✗ Incorrect
The method name is happy_hash, the key is symbol :smile, and the value is string "Keep happy!".