Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, Ruby!".
Ruby
puts [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text.
Using puts without quotes for strings.
✗ Incorrect
In Ruby, to print text, you use puts with the text inside quotes.
2fill in blank
mediumComplete the code to assign the number 10 to variable x.
Ruby
x = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes makes them strings.
Using variable name instead of value.
✗ Incorrect
In Ruby, to assign a number, write the number without quotes.
3fill in blank
hardFix the error in the code to add 5 to variable y.
Ruby
y = 7 sum = y [1] 5
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + changes the operation.
Using * or / does multiplication or division.
✗ Incorrect
Use + to add numbers in Ruby.
4fill in blank
hardFill both blanks to create a hash with keys as symbols and values as strings.
Ruby
person = { [1]: [2] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings as keys without colon.
Not quoting string values.
✗ Incorrect
In Ruby, hash keys can be symbols like :name, and values can be strings like "Alice".
5fill in blank
hardFill all three blanks to define a method that returns the square of a number.
Ruby
def [1](num) return num [2] num end result = [3](4)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Calling method with wrong name.
✗ Incorrect
Define method 'square', multiply num by num, then call square(4).