8. Practice makes perfect - help


#1



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

I'm not getting an error message, but the console will print true (as 9 is divisible by 3) but it won't print my name!! What am I doing wrong?


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

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

greeter("Annem")
by_three?(9)


#2

To see your output, use puts on both calls.

puts greeter("Annem")
puts by_three?(9)

#3

I had a similar problem. With return its not meant to use puts. But when I run the code it only prints the first method argument, i.e. in this case it skips the greeting and simply responds with the second argument result. My code is:

def greeter(name)
return "Hello #{name}"
end

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

puts greeter("Joe")
puts by_three?(14)

The result was only:

False

Greeting did not print. Am I missing something?


#4

Not to worry. The lesson doesn't ask us to print anything, only return.


#5

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