Simple Syntax error

Care to take a minute and help out a newbie? :wink:
I’ve tried everything I can think of, but I don’t come from a
programming background.

puts ‘What is your first name?’
first_name = gets.chomp
puts ‘Middle name?’
middle_name = gets.chomp
puts ‘Last name?’
last_name = gets.chomp
puts 'did you know there are ’ first_name + middle_name + last_name +
‘characters’
puts ‘in your name’ + first_name + middle_name + last_name + ‘?’

ERROR:

ruby length.rb
length.rb:7: syntax error, unexpected tIDENTIFIER, expecting $end
…ou know there are ’ first_name + middle_name + last_name + '…

Thanks a ton :slight_smile:

On Aug 7, 5:08 am, kook [email protected] wrote:

puts 'did you know there are ’ first_name + middle_name + last_name +
‘characters’

Because if you have a string delimited with ’ marks you have to escape
any ’ you put in the string.

Some general info about strings in ruby

Fred

And this is the corrected program.

puts ‘What is your first name?’
first_name = gets.chomp
puts ‘Middle name?’
middle_name = gets.chomp
puts ‘Last name?’
last_name = gets.chomp
full_name = first_name + middle_name + last_name
puts 'did you know there are ’ + full_name.length.to_s+'characters ’
'in your name ’ + full_name + ‘?’

Is that you need?

Sijo

kook wrote:

Care to take a minute and help out a newbie? :wink:
I’ve tried everything I can think of, but I don’t come from a
programming background.

You might like to work through some of the beginning-level tutorials
such as Try Ruby, then.

And please, ask your general Ruby questions on the Ruby list. They’re
off topic for the Rails list.

puts ‘What is your first name?’
first_name = gets.chomp
puts ‘Middle name?’
middle_name = gets.chomp
puts ‘Last name?’
last_name = gets.chomp
puts 'did you know there are ’ first_name + middle_name + last_name +
‘characters’
puts ‘in your name’ + first_name + middle_name + last_name + ‘?’

Syntax error or no, this program won’t do what you want. You need to
learn how to take the length of a string (look at the docs for class
String and you’ll find what you need).

ERROR:

ruby length.rb
length.rb:7: syntax error, unexpected tIDENTIFIER, expecting $end
…ou know there are ’ first_name + middle_name + last_name + '…

Thanks a ton :slight_smile:

You can’t have a string and a variable name next to each other without
an operator in between.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]