Bird
0
0

Given an array ["apple", "banana", "cherry"], how do you create a string where each fruit is separated by a semicolon and a space, like "apple; banana; cherry"?

hard📝 Application Q9 of 15
Ruby - String Operations
Given an array ["apple", "banana", "cherry"], how do you create a string where each fruit is separated by a semicolon and a space, like "apple; banana; cherry"?
A["apple", "banana", "cherry"].join('; ')
B["apple", "banana", "cherry"].split('; ')
C["apple", "banana", "cherry"].join(', ')
D["apple", "banana", "cherry"].split(', ')
Step-by-Step Solution
Solution:
  1. Step 1: Use join to combine array elements

    join takes a string separator to combine array elements into one string.
  2. Step 2: Use '; ' as separator

    Joining with '; ' produces the desired string with semicolon and space between fruits.
  3. Final Answer:

    ["apple", "banana", "cherry"].join('; ') -> Option A
  4. Quick Check:

    join('; ') creates semicolon-space separated string [OK]
Quick Trick: Use join with desired separator string [OK]
Common Mistakes:
MISTAKES
  • Using split on arrays
  • Joining with wrong separator
  • Confusing split and join methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes