Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Variables and Data Types
What will be the output of this Ruby code?
name = "Bob"
age = 25
puts "#{name} is #{age} years old."
A#{name} is #{age} years old.
BError: undefined variable
Cname is age years old.
DBob is 25 years old.
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable values

    Variables name and age hold "Bob" and 25 respectively.
  2. Step 2: Evaluate string interpolation

    The string uses #{name} and #{age} which will be replaced by their values.
  3. Final Answer:

    Bob is 25 years old. -> Option D
  4. Quick Check:

    Interpolation replaces variables with values [OK]
Quick Trick: Variables inside #{ } show their values in output [OK]
Common Mistakes:
  • Expecting interpolation inside single quotes
  • Confusing variable names with strings
  • Not assigning variables before interpolation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes