8 practice makes perfect


#1

I keep getting the error that i'm not defining my by_three? method. But i am.. aren't I?..

def greeter(name)
    return "Hey you" + name
end

def by_three?(number)
    if number % 3 == 0
        return True
    else
        return False
    end
end

#2

Try this out

def greeter(name)

return "Hello #{name}"
end

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

greeter("julian")
by_three?(555)
Remove the returns (true and false)
the question mark is already there to tell if the operation is false or true
for example
555 % 3 has a remainder of zero which is true...
so there is pretty much no need for the return true and return false


#3

true and false ---small case


#4

def greeter(name)
return "greeting" + name
end

def by_three?()
if n%3++0
return True
else
return False
end
end


#5

def greeter(name)
return "Hey you, #{name}!"
end

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

greeter("Julia")
by_three?(9)
by_three?(8)


RESULT:
"Hey you, Julia!"
true
false


#6

true and false should be small case
calling the method ( ex, by_three?(9) ) will show you the error in the editor, call your method every time you get an error. this way, Ruby will tell you what the problem is.


#7

def greeter(name)
return ("greeting"+name)
end
def by_three?(number)
(number %3 ==0)?(return true): (return false)
end
greeter("abc")
by_three?(30)

that answer


#8

I think it's not the issue of returning true/false. the problem that's giving the error is the greeter.
I had similar issue and I ran my code again after reading this forum for couple more times and it let me through. Nothing was changed. Code:

def greeter(name)
return "Hi #{name}!"
end
def by_three?(n)
return n % 3 == 0
end

greeter("James")
by_three?(3)