-4

name = "James Kirk", starship = "USS Enterprise" Given the variables above, write a Ruby expression that uses string interpolation in order to produce: "The captain of the USS Enterprise is James Kirk"

1 Answers1

0

So interpolation works like the following. You first need to have double quotes like using the ""'s. Then inside of those double quotes you just add the # and then the {} which contains the block of code that you want to run. So in this case you have 2 assignments:

 name = "James Kirk" 
 starship = "USS Enterprise"

Would result in you "interpolating" the variables in the string such as this:

what_you_want = "The captain of the #{starship} is #{name}"

Hope this helps! If not, please leave a comment and I'll elaborate.

Tony DiNitto
  • 1,244
  • 1
  • 16
  • 28
  • your variable assignment is a syntax error should be: name, starship = "James Kirk", "USS Enterprise" – LinkBerest Apr 17 '15 at 14:24
  • Thanks for pointing this out JGreenwell. I didn't think he would actually assign it like that, but some people might see it and actually incorrectly try to assign variables like that. I edited my answer for clarity. – Tony DiNitto Apr 17 '15 at 21:34