Bird
0
0

Which of these strings will correctly display the value of variable score inside the text?

easy📝 Conceptual Q2 of 15
Ruby - Variables and Data Types
Which of these strings will correctly display the value of variable score inside the text?
A'Your score is #{score}'
B"Your score is #{score}"
C"Your score is + score"
D'Your score is ' + score
Step-by-Step Solution
Solution:
  1. Step 1: Identify string types that support interpolation

    Only double-quoted strings support interpolation with #{}. Single quotes treat it as plain text.
  2. Step 2: Check each option

    "Your score is #{score}" uses double quotes and interpolation correctly. 'Your score is #{score}' uses single quotes, so no interpolation. Options C and D are incorrect syntax for interpolation.
  3. Final Answer:

    "Your score is #{score}" -> Option B
  4. Quick Check:

    Double quotes + #{ } = interpolation [OK]
Quick Trick: Use double quotes for interpolation, single quotes show text literally [OK]
Common Mistakes:
MISTAKES
  • Using single quotes expecting interpolation
  • Trying to concatenate inside double quotes without #{ }
  • Confusing string concatenation with interpolation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes