The Zen of Ruby 14


#1

Hi confused how to write string interpolation the below code seems to work but I don't pass the lesson:

favorite_things = ["Ruby", "espresso", "candy"]

puts "A few of my favorite things:"

favorite_things.each do |thing|
puts "I love " + thing + "!"
end

All I get is "Oops, try again. Make sure to use string interpolation in your code!"

so I try:

favorite_things = ["Ruby", "espresso", "candy"]

puts "A few of my favorite things:"

favorite_things.each do |thing|
puts "I love " + #[thing} + "!"
end

and get "Oops, try again. Your syntax doesn't look quite right. Check the examples in the instructions if you need help!"

Not sure what I am missing here can someone point out where I am going wrong?

Thanks,

Mark


#2

Hi that puts "I love " + #[thing} + "!" should be like that puts "I love #{thing}!"


#3

Thanks very much. The codeacademy console didn't give any output for puts "I love #{thing}! + "!"


#4

I modified the code slightly:

favorite_things = ["Ruby", "espresso", "candy", "lamp"]

puts "A few of my favorite things:"

favorite_things.each do |thing|
puts "I love #{thing}!"
end


#5

favorite_things = ["Ruby", "espresso", "candy"]

puts "A few of my favorite things:"

favorite_things.each do |thing|
puts "I love #{thing}!"
end