Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

ruby unexpected tIDENTIFIER

I am trying to do the extra credit for the Ruby Numbers badge. I think when I ran this code a couple of weeks ago it returned a product and now I get back a syntax error.

print "Enter the first factor to multiply "
    string_one = gets.chomp

print "Enter the second factor to multiply "
    string_two = gets.chomp

factor_1 = string_one.to_i

factor_2 = string_two.to_i

product = factor_1 * factor _2

puts product

The syntax error reads XC_numberone.rb:11: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('

I know I have to convert to floating point numbers and then format for the extra credit. That being said, I've tried a truncated version without getting the product and just puts-ing factor_1 and factor_2 and that works OK, so I figure my problem is in how I'm doing the product.

I also tried putting some "do"s and "end"s in there without any luck.

Any help is appreciated.

1 Answer

Here is your syntax error:

product = factor_1 * factor _2

you have a space between factor and _2.

Here is the fixed line

product = factor_1 * factor_2

after making that change it should run fine. Tricky error to catch there, took me a while to find it. everything looks fine at first glance.

Heh, that's an easy enough fix to understand. There have been lots of times folks have said how important it is to be careful typing code...

Thanks for your help!