Methods blocks and sorting exercise 8


#1

This is the link:
https://www.codecademy.com/en/courses/ruby-beginner-en-ET4bU/1/4?curriculum_id=5059f8619189a5000201fbcb

This is my code:

def greeter(name)
    return "Welcome" + " " + name
end
puts greeter("Emily")

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

puts by_three?(30)

This is my result:
Welcome Emily
true
nil

This is the error I am getting:
Oops, try again. It looks like your greeter method prints to the console instead of using return.

I don't know what it means? Can someone explain this to me. Thank you in advance.


#2

In the instructions, they say "don't use print or puts". Your error message is letting you know that the code checker has detected that you have used one or the other of those.


#3

ok. i understood that. but what would i put there instead. if I delete the entire line
puts greeter("Emily")
I would still get the same error!


#4

If it still gives that same error then it might be picking up on the puts by_three?(30) line.


#5

ok so what i did instead I used
output = greeter("Emily")

I did not get anything in the console! for this method.

though my second method worked after I changed to output = by_three?(30)
console printed:
true
nil


#6

For this exercise, it looks like they really don't want to see any output. Just use:

greeter("Emily")
by_three?(30)

#7

I see. Okay. thanks.

sometimes they want you to do less. Or not do something they thought you to do in an earlier expercise. why more practice is better for a newbie.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.