Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a range from 1 to 5 inclusive.
Ruby
range = 1 [1] 5 puts range.to_a
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the exclusive range operator (...) which excludes the last number.
Using arithmetic operators like + or - instead of range operators.
✗ Incorrect
The .. operator creates a range including the end value.
2fill in blank
mediumComplete the code to create a range from 1 to 5 excluding 5.
Ruby
range = 1 [1] 5 puts range.to_a
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the inclusive range operator (..) which includes the last number.
Using arithmetic operators like + or - instead of range operators.
✗ Incorrect
The ... operator creates a range excluding the end value.
3fill in blank
hardFix the error in the code to create a range from 'a' to 'e' inclusive.
Ruby
letters = 'a' [1] 'e' puts letters.to_a
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the exclusive range operator (...) which excludes the last letter.
Using arithmetic operators instead of range operators.
✗ Incorrect
Use the inclusive range operator .. to include 'e' in the range.
4fill in blank
hardFill both blanks to create a range from 10 to 20 excluding 20 and print its array.
Ruby
range = 10 [1] 20 puts range.[2].to_a
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inclusive range operator (..) which includes 20.
Using
to_s instead of to_a to convert the range.✗ Incorrect
Use the exclusive range operator ... to exclude 20, and to_a to convert the range to an array.
5fill in blank
hardFill all three blanks to create a range from 'm' to 'r' inclusive, convert it to an array, and print it.
Ruby
letters = 'm' [1] 'r' array = letters.[2] puts array.[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using exclusive range operator (...) which excludes 'r'.
Forgetting to convert the range to an array before joining.
Using
puts directly on the range without conversion.✗ Incorrect
Use .. for inclusive range, to_a to convert to array, and join to print as a string.