# Simple Syntax error

**URL:** <https://www.ruby-forum.com/t/simple-syntax-error/173360>\
**Category:** Rails\
**Created:** [August 7, 2009, 9:25am UTC](https://www.ruby-forum.com/t/simple-syntax-error/173360 "2009-08-07T09:25:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/13edae/32.png) [@kook](https://www.ruby-forum.com/u/kook)\
**Post date:** [August 7, 2009, 9:25am UTC](https://www.ruby-forum.com/t/simple-syntax-error/173360/1 "2009-08-07T09:25:40Z")

</div>

Care to take a minute and help out a newbie? 😉  
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 🙂

---

<div class="post-metadata">

**Author:** ![kook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/13edae/32.png) [@kook](https://www.ruby-forum.com/u/kook)\
**Post date:** [August 7, 2009, 9:32am UTC](https://www.ruby-forum.com/t/simple-syntax-error/173360/2 "2009-08-07T09:32:42Z")

</div>

On Aug 7, 5:08 am, kook [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

> **[Dev Trademarks - Alter](https://alter.com/trademarks/keywords/dev)**

> **[Ruby | zenspider.com | by ryan davis](https://www.zenspider.com/ruby/)**
>
> Ruby facts, opinions, source code, links, and stuff.

Fred

---

<div class="post-metadata">

**Author:** ![kook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/13edae/32.png) [@kook](https://www.ruby-forum.com/u/kook)\
**Post date:** [August 7, 2009, 9:38am UTC](https://www.ruby-forum.com/t/simple-syntax-error/173360/3 "2009-08-07T09:38:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/13edae/32.png) [@kook](https://www.ruby-forum.com/u/kook)\
**Post date:** [August 7, 2009, 3:47pm UTC](https://www.ruby-forum.com/t/simple-syntax-error/173360/4 "2009-08-07T15:47:55Z")

</div>

kook wrote:

> Care to take a minute and help out a newbie? 😉  
> 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 🙂

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid
