Bird
0
0

You want to create a method full_name that takes two arguments first and last and returns the full name as a single string separated by a space. Which code correctly does this?

hard📝 Application Q8 of 15
Ruby - Methods
You want to create a method full_name that takes two arguments first and last and returns the full name as a single string separated by a space. Which code correctly does this?
Adef full_name(first, last) first + " " + last end
Bdef full_name(first, last) first & last end
Cdef full_name(first, last) first, last end
Ddef full_name(first, last) "#{first}#{last}" end
Step-by-Step Solution
Solution:
  1. Step 1: Understand string concatenation

    To join two strings with a space, use first + " " + last.
  2. Step 2: Evaluate each option

    def full_name(first, last) first + " " + last end correctly concatenates with space. def full_name(first, last) first & last end uses & which is invalid for strings. def full_name(first, last) first, last end returns a comma-separated list, not a string. def full_name(first, last) "#{first}#{last}" end concatenates without space.
  3. Final Answer:

    def full_name(first, last) first + " " + last end -> Option A
  4. Quick Check:

    Use + and " " to join strings with space [OK]
Quick Trick: Use + " " + to join strings with space [OK]
Common Mistakes:
MISTAKES
  • Using & instead of +
  • Returning multiple values instead of string
  • Forgetting space between names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes