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

Syntax error

I've gone over this if statement several times and I keep getting the same error message: atomtest.rb:25: syntax error, unexpected tIDENTIFIER, expecting ':'
puts "Your number is divisible by 3!"
^
atomtest.rb:26: syntax error, unexpected keyword_else, expecting end-of-input

name = get_name() greet(name) number = get_number()

24: if (divisible_by_3)?(number) 25: puts "Your number is divisible by three" 26: else 27: puts "Your number is not cleanly divisible by three." 28: end

I even wrote the code separately and it seemed to work. This was copied from Atom into workspaces. What issue am I missing?

can you edit your post to display your code correctly following the guidelines found in the Markdown Cheatsheet link below the add comment/answer section, please? Or add a link to a fork of your Workspaces so we can see what's going on.

3 Answers

Mwagner. Can I just copy and past the link below? It's not a specific code challenge, it was just something I was trying in workspaces on my own.

Nathan Mahler - sure, but make sure you use the formatting markdown. Three backticks followed by the language (```ruby) on the line above the code, and then three backticks on a newline after your code.

Edit - Sorry, I misread what you said. You can definitely add a link to your Workspace fork if you'd prefer.

Tri Pham
Tri Pham
18,671 Points

Its probably thinking you are doing a ternary operator because of your question mark "?". (divisible_by_3)? should be divisible_by_3? if you did everything else correct.

Here is the code ''' if (divisible_by_3)?(number) puts "Your number is divisible by 3!" else puts "Your number is not cleanly divisible by three." end '''

The error message is as follows... atomtest.rb:25: syntax error, unexpected tIDENTIFIER, expecting ':'
puts "Your number is divisible by 3!"
^
atomtest.rb:26: syntax error, unexpected keyword_else, expecting end-of-input "

In case you want to look at the whole code the Workspaces link is https://teamtreehouse.com/workspaces/24727352 Tri Pham- I changed the question mark change and it didn't work.

PS Sorry it took me a few days to respond. I work full-time so coding only happens a few nights a week after work, and saturdays!

Tri Pham
Tri Pham
18,671 Points

is that all your code? Also your formatting is wrong and I get an error when I access your workspace.