Bird
0
0

You want to create a greeting message that includes a user's first and last name stored in variables first and last. Which code correctly uses string interpolation to produce "Hello, John Doe!"?

hard📝 Application Q8 of 15
Ruby - Variables and Data Types
You want to create a greeting message that includes a user's first and last name stored in variables first and last. Which code correctly uses string interpolation to produce "Hello, John Doe!"?
A"Hello, #{first} #{last}!"
B"Hello, #{first + last}!"
C"Hello, #{first}, #{last}!"
D"Hello, first last!"
Step-by-Step Solution
Solution:
  1. Step 1: Understand desired output format

    The greeting should show first and last name separated by a space.
  2. Step 2: Check each option's interpolation

    "Hello, #{first} #{last}!" inserts both variables with a space between them correctly. "Hello, #{first + last}!" concatenates without space. "Hello, #{first}, #{last}!" adds a comma which is not desired. "Hello, first last!" uses literal text.
  3. Final Answer:

    "Hello, #{first} #{last}!" -> Option A
  4. Quick Check:

    Use #{var} #{var} for spaced interpolation [OK]
Quick Trick: Use #{var} #{var} to insert multiple variables with space [OK]
Common Mistakes:
  • Concatenating without spaces inside interpolation
  • Adding unwanted punctuation
  • Using literal text instead of variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes