flux flux - 5 months ago 9
Ruby Question

Using a method to puts variables

I want to use

capitalize
method and
puts
a string with the user input.

puts "What is your name?"
name = gets.chomp
puts "Hi, " name.capitalize "how are you?"


Here is the error after line 2:


syntax error, unexpected tIDENTIFIER, expecting $end puts "Hi, "
name.capitalize "how are you?"

Answer

You need to use string interpolation. Here is a RubyMonk tutorial you may enjoy.

puts "Hi, #{name.capitalize}, how are you?"
Comments