0
0
Rubyprogramming~10 mins

Range operators (.. and ...) in Ruby - Interactive Code Practice

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

Complete 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'
A..
B...
C+
D-
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.
2fill in blank
medium

Complete 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'
A..
B...
C-
D+
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.
3fill in blank
hard

Fix 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'
A..
B+
C-
D...
Attempts:
3 left
💡 Hint
Common Mistakes
Using the exclusive range operator (...) which excludes the last letter.
Using arithmetic operators instead of range operators.
4fill in blank
hard

Fill 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'
A...
B..
Cto_a
Dto_s
Attempts:
3 left
💡 Hint
Common Mistakes
Using inclusive range operator (..) which includes 20.
Using to_s instead of to_a to convert the range.
5fill in blank
hard

Fill 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'
A..
Bto_a
Cjoin
D...
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.