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

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Defining these two method's. Is confusing any assistants?

Define two methods in the editor:

A greeter method that takes a single string parameter, name, and returns a string greeting that person. (Make sure to use return and don't use print or puts.) A by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and false if not.

This is what i got so far. An it tells me " (ruby):6: warning: string literal in condition "

def greeter?(name) return name end

def by_three?(number) return true if number % 3 == 0 number !% 3 == 0 return false end

1 Answer

Arturo Alviar
Arturo Alviar
15,739 Points

Hi Alphonse,

Your are getting an error due to your second method. Your logic is correct but there are a few errors with your syntax. When doing an inline conditional, you can only have one condition statement. It is legal to say

return true if number % 3 === 0

But you cannot have another condition statement after that.

In this case, you can use an else statement so it would look something like this:

def by_three?(number) 
 if number % 3 == 0 
  return true
 else
  return false 
 end

A simple way to write this method is by returning a boolean with just one line like so:

def by_three?(number) 
 return  number % 3 == 0 
end

Hope this helps!